title: Symfony2 Complex Query Builder M2M Having
body: <p>I am trying to do a complex search. Lets say for example I have a Book entity with Title &amp; Description properties and it is linked to Tags and Reviewers by many to many relationship.</p>
  
  <p>The closest I can get with a Query is the following:</p>
  
  <pre><code>     $qb = $this-&gt;createQueryBuilder('b')
          -&gt;leftJoin('b.tags', 't')
          -&gt;leftJoin('b.reviewers', 'r');
  
      $ands = $qb-&gt;expr()-&gt;andX();
  
      // Criteria Check
      $ors = $qb-&gt;expr()-&gt;orX();
      $ors-&gt;add($qb-&gt;expr()-&gt;like('b.title', ':criteria'));
      $ors-&gt;add($qb-&gt;expr()-&gt;like('b.description', ':criteria'));
      $ands-&gt;add($ors);
      $qb-&gt;setParameter('criteria', "%".$criteria."%");
  
      // Tags
      $ands-&gt;add($qb-&gt;expr()-&gt;in('t.id', ":tag_var"));
      $qb-&gt;setParameter("tag_var", [1,2]);
  
      // Reviewers
      $ands-&gt;add($qb-&gt;expr()-&gt;in('r.id', ":reviewer_var"));
      $qb-&gt;setParameter("reviewer_var", [3,4]);
  
      // Add the wheres
      $qb-&gt;where($ands);
      return $qb-&gt;getQuery()-&gt;getResult();
  </code></pre>
  
  <p>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?</p>