title: doctrine2 queryBuilder must return only result matching with array values (ids): 0/Null and/or One and/or Many id(s) have to return One result
body: <p>I have an array of collection named <code>$configurations</code>. This array matches of my Entity <code>Configuration.php</code> connected to <code>Product.php</code> as a <code>ManyToMany</code>. Now I have another entity named <code>WorkType.php</code> which is connected too to <code>Configuration.php</code> by a <code>ManyToMany</code>.</p>
  
  <p>The goal is to recover the product who has <code>O/Null</code> or <code>Many</code> configurations for the current work type.</p>
  
  <p>By default I have a product without configurations, but user could choose by checkboxes a <code>O/Null</code> or <code>One</code> or <code>Many</code> configurations available for a work type.</p>
  
  <p>So I created this queryBuilder in my <code>ProductRepository.php</code>:</p>
  
  <pre><code>public function getProductByManyConfig($slug, $configurations)
    {
  
      $queryBuilder = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
  
      $queryBuilder-&gt;select('p')
                   -&gt;from('MyBundle', 'p')
                   -&gt;join('p.workType', 'wt', 'WITH', 'wt.id = p.workType')
                   -&gt;leftJoin('p.configurations','c');
  
      $queryBuilder-&gt;add('where', $queryBuilder-&gt;expr()-&gt;in('c', ':c'))
                   -&gt;andWhere('wt.slug = :slug')
                   -&gt;setParameters(array('slug'=&gt; $slug, 'c'=&gt; $configurations));
  
      return $queryBuilder-&gt;getQuery()
                          -&gt;getResult();
    }
  </code></pre>
  
  <p>It works, but the proble is that it returns me all product matching with the array of configurations I pass to the query.</p>
  
  <p>For example if the array have the <code>id</code> <strong>1</strong> and <strong>2</strong> of <code>Configuration.php</code>, the query returns me the products matching with <strong>configuration.id = 1</strong>, <strong>configuration.id = 2</strong> and <strong>configuration.id =1 and 2</strong>. </p>
  
  <blockquote>
    <p>So I have 3 conditions to achieve, I need only one; e-g only the product which
    containing all the configuration.id !</p>
  </blockquote>
  
  <p>I only need to return the only one product containing the <code>ids</code> of <code>Configuration.php</code> passed into the array for the current <code>WorkType.php</code> !</p>
  
  <p>This is my controller code:</p>
  
  <pre><code>$vars = array(); //containing all values I need for recover configurations properties
  
  $em = $this-&gt;getDoctrine()-&gt;getManager();
  
  $var = array_values($vars);
  
  $configurations = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Configuration')-&gt;findByName($var);
  
  foreach ($configurations as $conf) {
    $name = $conf-&gt;getName();
  }
  
  $slug = "the_right_database_correspondence";
  
  $arrayProbuctConfig = $this-&gt;getDoctrine()-&gt;getRepository('MyBundle:Product')-&gt;getProductByManyConfig($slug, $configurations);
  
  // return of the view
  </code></pre>
  
  <p>As the choice of configurations could change, I need to create this dynamic method. How can I return the good result ?</p>