title: Doctrine query builder using inner join with conditions
body: <p>I'd like to construct the following SQL using Doctrine's query builder:</p>
  
  <pre><code>select c.*
  from customer c
  join phone p
  on p.customer_id = c.id
  and p.phone = :phone
  where c.username = :username
  </code></pre>
  
  <p>First I tried</p>
  
  <pre><code>$qb-&gt;select('c')
      -&gt;innerJoin('c.phones', 'p', Join::ON, $qb-&gt;expr()-&gt;andx(
          $qb-&gt;expr()-&gt;eq('p.customerId', 'c.id'),
          $qb-&gt;expr()-&gt;eq('p.phone', ':phone')
      ))
      -&gt;where('c.username = :username');
  </code></pre>
  
  <p>But I'm getting the following error</p>
  
  <pre><code>Error: expected end of string, got 'ON'
  </code></pre>
  
  <p>Then I tried</p>
  
  <pre><code>$qb-&gt;select('c')
      -&gt;innerJoin('c.phones', 'p')
      -&gt;where('c.username = :username')
      -&gt;andWhere('p.phone = :phone');
  </code></pre>
  
  <p>which seems to be working. However, does anyone know what's wrong with the first attempt? I'd like to make the first one work since it resembles more closely to how SQL is structured. Thanks in advance!</p>
  
  <p>Note: I know we can also write native mysql or dql with Doctrine, but I'd prefer query builder.</p>
  
  <p><strong>EDIT:</strong> Below is the entire code</p>
  
  <pre><code>namespace Cyan\CustomerBundle\Repository;
  
  use Cyan\CustomerBundle\Entity\Customer;
  use Doctrine\ORM\EntityRepository;
  use Doctrine\ORM\Query\Expr\Join;
  
  class CustomerRepository extends EntityRepository
  {
      public function findCustomerByPhone($username, $phone)
      {
          $qb = $this-&gt;createQueryBuilder('c');
  
          $qb-&gt;select('c')
              -&gt;innerJoin('c.phones', 'p', Join::ON, $qb-&gt;expr()-&gt;andx(
                  $qb-&gt;expr()-&gt;eq('p.customerId', 'c.id'),
                  $qb-&gt;expr()-&gt;eq('p.phone', ':phone')
              ))
              -&gt;where('c.username = :username');
  
  //        $qb-&gt;select('c')
  //            -&gt;innerJoin('c.phones', 'p')
  //            -&gt;where('c.username = :username')
  //            -&gt;andWhere('p.phone = :phone');
  
          $qb-&gt;setParameters(array(
              'username' =&gt; $username,
              'phone' =&gt; $phone-&gt;getPhone(),
          ));
  
          $query = $qb-&gt;getQuery();
          return $query-&gt;getResult();
      }
  }
  </code></pre>