I have the following query that uses an IN statement.
$ids = array(1,2,3);
$query = 'select o from Organisation o where o.id in (:ids)';
$this->_entityManager->createQuery($query)
->setParameter('ids', implode(', ', $ids))
Doctrine is not returning any results, I think it is because of something wrong in the conversion that Doctrine does for the passed parameter $ids
which is an array.
How to make it work?
Try passing the array itself to
->setParameter(...)
instead of imploding it into a string.I used this (setParameter didn't seem to work for me):
http://redbeardtechnologies.wordpress.com/2011/07/01/doctrine-2-dql-in-statement/
I'm struggling with the IN statement too, using the $query->expr()->in() construct...
Try:
I think the simple quotes around your parameters in the IN() part are necessary...
I solved this: