I have 2 entities: author and person.
In the author entity, there is a person field which is in fact the person object:
/**
* @ORM\ManyToOne(targetEntity="Person", inversedBy="submission_authors")
* @ORM\JoinColumn(name="person_id", referencedColumnName="id")
*/
protected $person;
Now, in the repository: AuthorRepository, I would like to search for some authors by their firstname. To do this, I need to access the person object for the corresponding author ans look on the person's firstname.
I tryed:
public function searchAuthors($q)
{
$authQB = $this->createQueryBuilder( 'a' )
->select('a')
->where("a.person.firstname LIKE '%".$q."%'");
return $authQB->getQuery()->getResult();
}
But the problem is that I am geting an error:
[Syntax Error] line 0, col 78: Error: Expected Doctrine\ORM\Query\Lexer::T_LIKE, got '.'
Coud you please help me on how to resolve that?
You'd have to access your
person
relation like this:To learn a bit more about query builder and joint tables:
Try