I am trying to do a query where I have an entity Job
and an entity JobProperty
where 1 Job
can have many JobProperties
.
Query on a many-to-many relationship using Doctrine with Symfony2 explains how to retrieve matches on one entity based on values of it's subEntities. From this I have built the query:
$qb = $this->getDoctrine()->getRepository('AppBundle:Job')->createQueryBuilder('job')
->innerJoin('job.properties','property');
foreach($filters as $label => $value)
{
$qb->andWhere('property.label = :label AND property.value = :value')
->setParameter('label',$label)
->setParameter('value',$value);
}
The query above works to an extent, but it provides results where a property matches against ANY of the filters, and does not only provide results where ALL filters are matched. I need it to return only results where ALL filters are matched.
I might have to go about this in a different way, but I'm not sure I would implement.