Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF2][Symfony2][Symfony] Złe złączenie encji, Repository class
damianooo
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

Ostrzeżenie: (0%)
-----


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 ?

Ten post edytował damianooo 17.01.2016, 15:37:32
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
404
post
Post #2





Grupa: Zarejestrowani
Postów: 226
Pomógł: 25
Dołączył: 22.05.2011

Ostrzeżenie: (0%)
-----


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. //...
?

Ten post edytował 404 17.01.2016, 19:06:33
Go to the top of the page
+Quote Post
damianooo
post
Post #3





Grupa: Zarejestrowani
Postów: 496
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Miałeś rację to był problem.

Dzięki, Pozdrawiam
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 04:04