I am trying to do a complex search. Lets say for example I have a Book entity with Title & Description properties and it is linked to Tags and Reviewers by many to many relationship.
The closest I can get with a Query is the following:
$qb = $this->createQueryBuilder('b')
->leftJoin('b.tags', 't')
->leftJoin('b.reviewers', 'r');
$ands = $qb->expr()->andX();
// Criteria Check
$ors = $qb->expr()->orX();
$ors->add($qb->expr()->like('b.title', ':criteria'));
$ors->add($qb->expr()->like('b.description', ':criteria'));
$ands->add($ors);
$qb->setParameter('criteria', "%".$criteria."%");
// Tags
$ands->add($qb->expr()->in('t.id', ":tag_var"));
$qb->setParameter("tag_var", [1,2]);
// Reviewers
$ands->add($qb->expr()->in('r.id', ":reviewer_var"));
$qb->setParameter("reviewer_var", [3,4]);
// Add the wheres
$qb->where($ands);
return $qb->getQuery()->getResult();
Which works great if for example a book is linked to least 1 tag but what I am trying to ascertain is how to get the results based if a book has both ids that I have set for the tags?