Question

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

return 
$this->createQueryBuilder('c')
->select('c')
->from('Sdz\BlogBundle\Entity\Commentaire' ,'c')                
->leftJoin('a.comments' ,'c')->getQuery()->getResult() ;

but I'm getting this error

[Semantical Error] line 0, col 58 near '.comments c,': Error:
Identification Variable a used in join path expression but was not defined before.

PS : The mapping is correct because I can see the page article with its comments.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top