I have been working some days with a dql problem.
In my model, y have 2 entities (machine and instance). Is a one-to-many relation, so a machina could have many instances, and an Instance only can have 1 machine.
Now, I want to get all machines which has some Instances. In normal dql i get it work correctly like that:
$ids = array(...)
$dql = "select M from AppBundle:Machine M INNER JOIN AppBundle:Instancia I WITH M.id = I.machine WHERE I.software IN (:ids)";
$query = $em->createQuery($dql)->setParameter('ids', $ids);
$maquinas = $query->getResult();
But when I want to translate in a QueryBuilder i'm not getting it to work. I'm triying some ways:
//First way
$qb = $this->createQueryBuilder("M")
->innerJoin('Instancia', 'I', 'WITH', 'M.id = I.machine')
->where('I.software IN (:ids)')
->setParameters('ids', $ids);
$maquinas = $qb->getQuery()->getResult();
//Second way
$qb = $this->createQueryBuilder("x")
->select('M')
->from('AppBundle:Machine', 'M')
->innerJoin('Instancia', 'I', 'WITH', 'M.id = I.machine')
->where('I.software IN (:ids)')
->setParameters('ids', $ids);
$maquinas = $qb->getQuery()->getResult();
What is my fault?
Which way is more faster, simple dql or a querybuilder??
Thank a lot!!