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

Closed
opened 2026-01-22 12:30:47 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 21, 2009).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user mcurcio:

This is my desired final product:

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

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.

Originally created by @doctrinebot on GitHub (Nov 21, 2009). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user mcurcio: This is my desired final product: ``` $users = $em->createQuery('SELECT FROM User u WHERE u.id IN :ids') ->setParameter('ids' => array(1, 2, 3)) ->execute() ``` 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.
admin added the Improvement label 2026-01-22 12:30:47 +01:00
admin closed this issue 2026-01-22 12:30:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 13, 2010):

Comment created by mcurcio:

Can we call this a 2.0beta improvement?

@doctrinebot commented on GitHub (Jan 13, 2010): Comment created by mcurcio: Can we call this a 2.0beta improvement?
Author
Owner

@doctrinebot commented on GitHub (May 6, 2010):

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();

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

$result = $qb->execute();
// or via EntityRepository
$qb = $em->getRepository('User')->createQueryBuilder('u');
$qb->where($qb->expr()->in('u.id', array(1, 2, 3));
$result = $qb->execute();
@doctrinebot commented on GitHub (May 6, 2010): 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(); $qb->select('u') ->from('User', 'u') ->where($qb->expr()->in('u.id', array(1, 2, 3)); $result = $qb->execute(); ``` ``` // or via EntityRepository $qb = $em->getRepository('User')->createQueryBuilder('u'); $qb->where($qb->expr()->in('u.id', array(1, 2, 3)); $result = $qb->execute(); ```
Author
Owner

@doctrinebot commented on GitHub (May 13, 2011):

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: 8e3fdc5adc
It is now possible to do that without having to manually define a parameter type (which smartly converts into valid data types).

Regards,

@doctrinebot commented on GitHub (May 13, 2011): 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: https://github.com/doctrine/doctrine2/commit/8e3fdc5adc0facd4b44f9054ab3681e46131ba8a It is now possible to do that without having to manually define a parameter type (which smartly converts into valid data types). Regards,
Author
Owner

@doctrinebot commented on GitHub (May 13, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 13, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#209