Doctrine query WHERE IN - many to many
<p>I am building out a hotel website in Symfony2. Each hotel can provide many board basis options such as Self Catering, All-Inclusive etc.</p>

<p>On my search form the users can filter by all of the usual fields such as location, price, star rating and board basis. Board basis is a multiple select check box.</p>

<p>When a user selects multiple board basis options, I am currently handling it in this way... (which is throwing errors)</p>

<pre><code>$repo = $this-&gt;getDoctrine()-&gt;getRepository("AppBundle:Accommodation");

$data = $form-&gt;getData();

$qb = $repo-&gt;createQueryBuilder("a")
        -&gt;innerJoin("AppBundle:BoardType", "b")
        -&gt;where("a.destination = :destination")
        -&gt;setParameter("destination", $data['destination'])
        -&gt;andWhere("a.status = 'publish'");

if (count($data['boardBasis']) &gt; 0) {
    $ids = array_map(function($boardBasis) {
        return $boardBasis-&gt;getId();
    }, $data['boardBasis']-&gt;toArray());

    $qb-&gt;andWhere($qb-&gt;expr()-&gt;in("a.boardBasis", ":ids"))
        -&gt;setParameter("ids", $ids);
}
</code></pre>

<p>Here is the property declaration on a hotel entity</p>

<pre><code>/**
 * @ORM\ManyToMany(targetEntity="BoardType")
 * @ORM\JoinTable(name="accommodation_board_type",
 *      joinColumns={@ORM\JoinColumn(name="accommodation_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="board_type_id", referencedColumnName="id")}
 *      )
 */
private $boardBasis;
</code></pre>

<p>The error I am currently getting is:</p>

<blockquote>
  <p>[Semantical Error] line 0, col 177 near 'boardBasis I': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected. </p>
</blockquote>

<p>On submitting the form and using <code>var_dump</code> on the board types I am getting:</p>

<pre><code>object(Doctrine\Common\Collections\ArrayCollection)[3043]
  private 'elements' =&gt; 
    array (size=2)
      0 =&gt; 
        object(AppBundle\Entity\BoardType)[1860]
          protected 'shortCode' =&gt; string 'AI' (length=2)
          protected 'id' =&gt; int 1
          protected 'name' =&gt; string 'All-Inclusive' (length=13)
          protected 'description' =&gt; null
          protected 'slug' =&gt; string 'all-inclusive' (length=13)
          protected 'created' =&gt; 
            object(DateTime)[1858]
              ...
          protected 'updated' =&gt; 
            object(DateTime)[1863]
              ...
      1 =&gt; 
        object(AppBundle\Entity\BoardType)[1869]
          protected 'shortCode' =&gt; string 'BB' (length=2)
          protected 'id' =&gt; int 2
          protected 'name' =&gt; string 'Bed &amp; Breakfast' (length=15)
          protected 'description' =&gt; null
          protected 'slug' =&gt; string 'bed-breakfast' (length=13)
          protected 'created' =&gt; 
            object(DateTime)[1867]
              ...
          protected 'updated' =&gt; 
            object(DateTime)[1868]
              ...
</code></pre>

<p>I cannot seem to find the correct syntax for this query, I have done a few times in the past (and it was a pain each time), but I just cannot remember how it is done. I have tried without mapping the ID's, passing the <code>ArrayCollection</code> directly in.</p>

<p>The only thing I can think of at the moment is to switch it to using <code>createQuery</code> and using DQL and see if that makes any difference.</p>

<p>Any help with this issue would be appreciated, Thank you</p>