Reputation: 2237
So i have the following doctrine query:
$qb = $this->createQueryBuilder('c')
->select('c','g')
->join('c.descendant', 'g');
$qb2 = $this->createQueryBuilder('c2')
->select('c2.id')
->addOrderBy('c2.ancestor', 'ASC');
if ($params['rootGroup']) {
$qb2->where('c2.ancestor = :groupId')
->setParameter('groupId', $params['rootGroup']->getId());
}
$in = $qb->expr()->in('g.id', $qb2->getDQL());
$qb->where($in);
when I run the getQuery() i got the following exception message:
Invalid parameter number: number of bound variables does not match number of tokens
I dump my DQL and i got the following:
"SELECT c, g FROM CI\GroupBundle\Entity\GroupClosure c INNER JOIN c.descendant g WHERE g.id IN(SELECT c2.id FROM CI\GroupBundle\Entity\GroupClosure c2 WHERE c2.ancestor = :groupId ORDER BY c2.ancestor ASC)"
I also dump the getParameter() of $qb and $qb2 and I got empty array for $qb and an array with 1 Parameter object on $qb2.
I really dont know whats wrong with my query since i expecting that i should bound only 1 value.
Thanks.
Upvotes: 1
Views: 309
Reputation: 5679
->setParameter('groupId', $params['rootGroup']->getId())
move it to $qb. getDQL()
returns dql with parameters names, not values.
Upvotes: 2