Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

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.

@doctrinebot

Comment created by mcurcio:

Can we call this a 2.0beta improvement?

@doctrinebot

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

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).

Regards,

@doctrinebot

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.