title: Symfony2 : Find through several entities
body: <p>I'm facing an issue while searching through several entities with Doctrine2.</p>
  
  <p>I have an entity People joined to another entity Email on a "OneToMany" relationship :</p>
  
  <pre><code>&lt;?php
  class People
  {
    // ...
    /**
     * @ORM\OneToMany(targetEntity="Email", mappedBy="people")
     */
    protected $emails;
    // ...
  }
  
  class Email
  {
    // ...
    /**
     * @ORM\ManyToOne(targetEntity="People", inversedBy="emails")
     * @ORM\JoinColumn(name="id", referencedColumnName="id")
     */
    protected $people;
  }
  </code></pre>
  
  <p>In my PeopleRepository, I try to do something like this :</p>
  
  <pre><code>$queryBuilder = $this-&gt;_em-&gt;createQueryBuilder()
                    -&gt;select('p')
                    -&gt;from('MyBundle:People', 'p')
                    -&gt;leftJoin('p.emails', 'e')
                    -&gt;where('p.name LIKE :name')
                    -&gt;andWhere('p.firstName LIKE :firstName')
                    -&gt;andWhere('e.email LIKE :email')
                    -&gt;setParameter('name', '%'.$name.'%')
                    -&gt;setParameter('firstName', '%'.$firstName.'%')
                    -&gt;setParameter('email', '%'.$email.'%');
  </code></pre>
  
  <p>But the email condition doesn't seem to be interpreted. I would like to get a response with the People entity, corresponding to the email attribute from the Email entity it's linked to.</p>
  
  <p>I don't know if what I say is clear enough.</p>
  
  <p>But if anyone understood my issue, do know how I could do ?</p>
  
  <p>Thank you :)</p>