Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [SF2][Symfony2][Symfony] Złe złączenie encji
Forum PHP.pl > Forum > PHP > Frameworki
damianooo
Mam encję "Match" złączoną w poniższy sposób z encją "Team" :

  1. /**
  2.   * @ORM\ManyToOne(
  3.   * targetEntity = "Team"
  4.   * )
  5.   *
  6.   * @ORM\JoinColumn(
  7.   * name = "hostTeam_id",
  8.   * referencedColumnName = "id",
  9.   * onDelete = "SET NULL"
  10.   * )
  11.   */
  12. private $hostTeam;
  13.  
  14. /**
  15.   * @ORM\ManyToOne(
  16.   * targetEntity = "Team"
  17.   * )
  18.   *
  19.   * @ORM\JoinColumn(
  20.   * name = "guestTeam_id",
  21.   * referencedColumnName = "id",
  22.   * onDelete = "SET NULL"
  23.   * )
  24.   */
  25. private $guestTeam;


W klasie Repository Class w jednej z funkcji potrzebuję wykonać złączenie encji "Match" z "Team" :

  1. public function getTypesPerUser($matchday){
  2.  
  3. $qb = $this->createQueryBuilder('t');
  4. $qb->select(
  5. 'tm1.name AS host'
  6. ,'tm2.name AS guest'
  7. ,'t.hostType'
  8. ,'t.guestType'
  9. ,'u.id AS user'
  10. ,'md.id AS matchday'
  11. )
  12. ->innerJoin('t.match', 'm')
  13. ->innerJoin('m.team', 'tm1')
  14. ->innerJoin('m.team', 'tm2')
  15. ->innerJoin('m.matchday', 'md')
  16. ->innerJoin('t.user', 'u')
  17. ->where('md.id = :matchday')
  18. ->setParameter('matchday', $matchday)
  19. ;
  20.  
  21. $result = $qb->getQuery()->getResult();
  22. }


Niestety otrzymuję następujący błąd:

  1. [Semantical Error] line 0, col 176 near 'tm1 INNER JOIN': Error: Class My\TyperkaBundle\Entity\Match has no association named team


Taki select (działający w phpmyadmin) powinien z tego wyjść:

  1. SELECT
  2. tm1.name AS host,
  3. tm2.name AS guest,
  4. t.hostType,
  5. t.guestType,
  6. u.id AS user,
  7. md.id AS matchday
  8. FROM types t
  9. INNER JOIN matches m ON t.match_id = m.id
  10. INNER JOIN teams tm1 ON m.hostTeam_id = tm1.id
  11. INNER JOIN teams tm2 ON m.guestTeam_id = tm2.id
  12. INNER JOIN matchdays md ON m.matchday_id = md.id
  13. INNER JOIN users u ON t.user_id = u.id
  14. WHERE md.id = 1


Co robię źle w query builderze ?
404
Czy zamiast:
  1. //...
  2. ->innerJoin('m.team', 'tm1')
  3. ->innerJoin('m.team', 'tm2')
  4. //...
Nie powinno być:
  1. //...
  2. ->innerJoin('m.hostTeam', 'tm1')
  3. ->innerJoin('m.guestTeam', 'tm2')
  4. //...
?
damianooo
Miałeś rację to był problem.

Dzięki, Pozdrawiam
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.