title: symfony doctrine complex querybuilder
body: <p>Maybe something simple but my query builder doesn't return what I want. I would something like ... where ... AND (.... OR ....)</p>
  
  <p>I try to read the doctrine doc but, I'm not fluent english so I don't really understand the doctrine doc (maybe a translation in french is available ?).</p>
  
  <pre><code>&lt;?php
  // $qb instanceof QueryBuilder
  
  $qb-&gt;select(array('u')) // string 'u' is converted to array internally
     -&gt;from('User', 'u')
     -&gt;where($qb-&gt;expr()-&gt;orX(
         $qb-&gt;expr()-&gt;eq('u.id', '?1'),
         $qb-&gt;expr()-&gt;like('u.nickname', '?2')
     ))
     -&gt;orderBy('u.surname', 'ASC'));
  </code></pre>
  
  <p><strong>Here is my MySQL test code that work</strong></p>
  
  <pre><code>select count(distinct(u.username)) from fos_user u join users_accounts ua ON u.id=ua.user_id join account acc ON acc.id = ua.account_id where u.id=48 and (acc.id=2 OR acc.id=5)
  </code></pre>
  
  <p><strong>Here is the query builder :</strong></p>
  
  <p>I use a service because I had to use this functionality more than once.</p>
  
  <pre><code>/**
  * Check if User exists in one of the connected user (Admin or SupAdmin) accounts
  * argument : userID
  * 
  */
  public function userExists($userID)
      {       
          // Return accounts (array)
          $accounts   = $this-&gt;accountManager-&gt;listAccountsByConnectedUser();
          $repository = $this-&gt;em-&gt;getRepository('CMiNewsBundle:User');
  
          $qb = $repository-&gt;createQueryBuilder('u');
  
          $query = $qb
                      -&gt;select('count(u)')
                      -&gt;join ('u.accounts', 'acc')
                      -&gt;where('u.id = :userID')
                      -&gt;andwhere('acc.id = :accountID')
                      -&gt;setParameters(array(
                        'userID'  =&gt; $userID,
                        'accountID'  =&gt; $accounts[0]-&gt;getId(),
                      ));
  
                     if (count($accounts) &gt; 1) {
  
  
                      $accountMax = count($accounts);                         
  
                      for($acc=1; $acc&lt;$accountMax; $acc++)
                      {
                          $query-&gt;orWhere('acc.id = :accountID_'.$acc.'')-&gt;setParameter('accountID_'.$acc.'', $accounts[$acc]-&gt;getId());
                      }
                     };
  
                     $query = $query-&gt;getQuery();
                     $result = $query-&gt;getResult();
          return $result;
      }
  </code></pre>
  
  <p>Thank you for your advices</p>