/** * @ORM\ManyToOne( * targetEntity = "Team" * ) * * @ORM\JoinColumn( * name = "hostTeam_id", * referencedColumnName = "id", * onDelete = "SET NULL" * ) */ private $hostTeam; /** * @ORM\ManyToOne( * targetEntity = "Team" * ) * * @ORM\JoinColumn( * name = "guestTeam_id", * referencedColumnName = "id", * onDelete = "SET NULL" * ) */ private $guestTeam;
W klasie Repository Class w jednej z funkcji potrzebuję wykonać złączenie encji "Match" z "Team" :
public function getTypesPerUser($matchday){ $qb = $this->createQueryBuilder('t'); $qb->select( 'tm1.name AS host' ,'tm2.name AS guest' ,'t.hostType' ,'t.guestType' ,'u.id AS user' ,'md.id AS matchday' ) ->innerJoin('t.match', 'm') ->innerJoin('m.team', 'tm1') ->innerJoin('m.team', 'tm2') ->innerJoin('m.matchday', 'md') ->innerJoin('t.user', 'u') ->where('md.id = :matchday') ->setParameter('matchday', $matchday) ; $result = $qb->getQuery()->getResult(); }
Niestety otrzymuję następujący błąd:
[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ść:
SELECT tm1.name AS host, tm2.name AS guest, t.hostType, t.guestType, u.id AS user, md.id AS matchday FROM types t INNER JOIN matches m ON t.match_id = m.id INNER JOIN teams tm1 ON m.hostTeam_id = tm1.id INNER JOIN teams tm2 ON m.guestTeam_id = tm2.id INNER JOIN matchdays md ON m.matchday_id = md.id INNER JOIN users u ON t.user_id = u.id WHERE md.id = 1
Co robię źle w query builderze ?