Skip to content


DDC-170: Smarter IN() query mapping #2348

doctrinebot opened this Issue · 4 comments

2 participants


Jira issue originally created by user mcurcio:

This is my desired final product:

$users = $em->createQuery('SELECT FROM User u WHERE IN :ids')
->setParameter('ids' => array(1, 2, 3))

I am currently using unpleasant methods of generating strings of '?' to insert into the DQL, which is not quite as elegant as the rest of the DQL language.


Comment created by mcurcio:

Can we call this a 2.0beta improvement?


Comment created by mjh_ca:

Agree it would be nice via setParameter. But, this can already be accomplished via QueryBuilder expr(). For example:

// directly from EntityManager
$qb = $em->createQueryBuilder();

   ->from('User', 'u')
   ->where($qb->expr()->in('', array(1, 2, 3));

$result = $qb->execute();
// or via EntityRepository
$qb = $em->getRepository('User')->createQueryBuilder('u');
$qb->where($qb->expr()->in('', array(1, 2, 3));
$result = $qb->execute();

Comment created by @guilhermeblanco:

Currently it's possible to send an array of parameters that can perfectly fix this.
Here is a sample for consideration:

$query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username IN (?0)");
$query->setParameter(0, array('beberlei', 'jwage'));

$users = $query->execute();

$this->assertEquals(2, count($users));

With the last commit: 8e3fdc5
It is now possible to do that without having to manually define a parameter type (which smartly converts into valid data types).



Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.1 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.