Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

createQueryBuilder IN clause

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.

like image 632
ikerib Avatar asked Nov 30 '22 15:11

ikerib


1 Answers

Missing parentheses after the IN operator :

->where('det.id IN (:miarray)')
->setParameter('miarray', array('143','144'))
like image 94
webda2l Avatar answered Dec 30 '22 00:12

webda2l