I'm facing an issue while searching through several entities with Doctrine2.
I have an entity People joined to another entity Email on a "OneToMany" relationship :
<?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;
}
In my PeopleRepository, I try to do something like this :
$queryBuilder = $this->_em->createQueryBuilder()
->select('p')
->from('MyBundle:People', 'p')
->leftJoin('p.emails', 'e')
->where('p.name LIKE :name')
->andWhere('p.firstName LIKE :firstName')
->andWhere('e.email LIKE :email')
->setParameter('name', '%'.$name.'%')
->setParameter('firstName', '%'.$firstName.'%')
->setParameter('email', '%'.$email.'%');
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.
I don't know if what I say is clear enough.
But if anyone understood my issue, do know how I could do ?
Thank you :)