Reputation: 1398
I'm trying to execute an inner query and set parameters without success, i always get:
Invalid parameter number: number of bound variables does not match number of tokens
This is my query :
SELECT i2
FROM MyBundle:Identity i2
INNER JOIN MyBundle:Property\\Mapped\\Email propertyEmail WITH propertyEmail.identity = i2
INNER JOIN MyBundle:Channel channel WITH propertyEmail.channel = channel
WHERE (
SELECT COUNT(mappedEmail)
FROM MyBundle:Property\\Mapped\\Email mappedEmail
WHERE mappedEmail.identity = i2
AND mappedEmail.channel = :channel
AND mappedEmail.createdAt <= :dateFrom
) > 0
AND IDENTITY(propertyEmail.channel) <> :channel
AND propertyEmail.createdAt <= :dateFrom
GROUP BY i2
And this is how i put as subquery:
$innerQuery = $queryBuilder->getEntityManager()->createQuery($query)
->setParameters([
'channel' => $channelId,
'dateFrom' => $dateFrom
])
;
$queryBuilder->andWhere($queryBuilder->expr()->notIn($alias, $innerQuery->getDQL()));
That return the error :
Invalid parameter number: number of bound variables does not match number of tokens
If I execute the query as single query all works right.
Thanks for suggestion.
Upvotes: 2
Views: 707
Reputation: 39460
Try to apply the parameters to the main query as follow:
$innerQuery = $queryBuilder->getEntityManager()->createQuery($query);
$queryBuilder
->andWhere($queryBuilder->expr()->notIn($alias, $innerQuery->getDQL()))
->setParameters([
'channel' => $channelId,
'dateFrom' => $dateFrom
]);
Upvotes: 2