Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        mcurcio Matt Curcio added a comment -

        Can we call this a 2.0beta improvement?

        Show
        mcurcio Matt Curcio added a comment - Can we call this a 2.0beta improvement?
        Hide
        mjh_ca Marc Hodgins added a comment -

        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();
        
        Show
        mjh_ca Marc Hodgins added a comment - 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();
        Hide
        guilhermeblanco Guilherme Blanco added a comment -

        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,

        Show
        guilhermeblanco Guilherme Blanco added a comment - 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,

          People

          • Assignee:
            guilhermeblanco Guilherme Blanco
            Reporter:
            mcurcio Matt Curcio
          • Votes:
            9 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: