createQueryBuilder IN clause
Asked Answered
D

1

5

I´m working with Symfony2 and I need to execute this SQL for example:

      select detformacion.* from detformacion
        left  join formacion
        on detformacion.formacion_id = formacion.id
        left join detcurso
        on formacion.id = detcurso.formacion_id
        where detcurso.id IN ('143','144');

For that, I have this in my Repository:

public function getSeleccion() {

    $em = $this->getEntityManager();

    $query = $em->createQueryBuilder()
                ->select('d')
            ->from('GitekUdaBundle:Detformacion', 'd')
            ->leftJoin('d.formacion', 'f') 
                ->leftJoin('f.detcursos', 'det')
                ->where('det.id = :miarray')
                ->setParameter('miarray',array('143','144'))
            ->getQuery() 
            ;
      return $query->getResult();
    }

I tried with ->where('det.id IN :miarray') but I´m getting errors all the time.

Any help or clue?

thanks in advance.

UPDATE: The problem is setting the parameters.

Deconsecrate answered 26/10, 2011 at 9:24 Comment(0)
M
22

Missing parentheses after the IN operator :

->where('det.id IN (:miarray)')
->setParameter('miarray', array('143','144'))
Murchison answered 26/10, 2011 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.