title: Doctrine 2 manyToMany relation Selecting Entity with AND
body: <p>I'm building a website which needs the ability to filter villa's based on their options. So for example: A villa has the options: Wi-Fi, Pool, Animals allowed. </p>
  
  <p>When filtering I'm giving the options: Wi-Fi and Pool. I now need a filtered list of villa's based on BOTH these options. So I only want the villa's that have both Wi-Fi AND a Pool. </p>
  
  <p>My Villa Entity looks like this:</p>
  
  <pre><code>class Object
  {
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=255)
   */
  private $name;
  
  /**
   * @ORM\manyToMany(targetEntity="Option", mappedBy="objects")
   */
  private $options;
  
  //...
  }
  </code></pre>
  
  <p>And my Option Entity looks like this:</p>
  
  <pre><code>class Option
  {
  
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=255)
   */
  private $tag;
  
  /**
   * @ORM\manyToMany(targetEntity="Object", inversedBy="options")
   * @ORM\JoinTable(name="Object_Options")
   */
  private $objects;
  
  //...
  }
  </code></pre>
  
  <p>I have an array of filter ids <code>$filters</code> with which I need to filter. </p>
  
  <p>I just can't seem to figure out how to accomplish this. </p>
  
  <p>I now have this</p>
  
  <pre><code>$qb = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  $qb-&gt;select("o")-&gt;from("Object", "o");
  
  if ($filters &amp;&amp; count($filters) &gt; 0) {
      $qb-&gt;innerJoin("o.options", "f");
      $qb-&gt;andWhere($qb-&gt;expr()-&gt;in("f.id", $filters));
  }
  
  $query = $qb-&gt;getQuery();
  </code></pre>
  
  <p>but this actually does the opposite of what I need. This filters villa's based on the options but uses OR instead of AND. So this gives me results for where a Villa has Wi-Fi OR a Pool. </p>
  
  <p>So in pseudo code I need: </p>
  
  <pre><code>get all Objects that have every given option (and maybe more)
  </code></pre>
  
  <p>Can any one shed some light on this?</p>