我正在尝试获取主页中每个帖子的所有评论
return
$this->createQueryBuilder('c')
->select('c')
->from('Sdz\BlogBundle\Entity\Commentaire' ,'c')
->leftJoin('a.comments' ,'c')->getQuery()->getResult() ;
但我收到此错误
[Semantical Error] line 0, col 58 near '.comments c,': Error:
Identification Variable a used in join path expression but was not defined before.
PS:映射是正确的,因为我可以看到页面文章及其注释。
最佳答案
万一这仍然给您带来问题,请使用Doctrine 2.1文档中示例中的语法进行查询。
我假设您的查询驻留在自定义存储库方法中,并且“ a”是“ Article”的缩写。
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb->select(array('a', 'c'))
->from('Sdz\BlogBundle\Entity\Article', 'a')
->leftJoin('a.comments', 'c');
$query = $qb->getQuery();
$results = $query->getResult();
return $results;
关于doctrine-orm - 教义2查询生成器和联接表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8031321/