doctrine 2 query builder and join tables

后端 未结 1 802
遥遥无期
遥遥无期 2020-12-16 12:18

I\'m trying to get all comments for each post in my home page

return 
$this->createQueryBuilder(\'c\')
->select(\'c\')
->from(\'Sdz\\BlogBundle\\En         


        
相关标签:
1条回答
  • 2020-12-16 12:50

    In case this is still giving you problems, here is your query using the syntax found in the examples in the Doctrine 2.1 documentation.

    I'm assuming your query resides in a custom repository method, and that 'a' is an abbreviation for '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;
    
    0 讨论(0)
提交回复
热议问题