Reputation: 2406
I have two simple entities A and B : (entity 'AB' automatically created by symfony 4)
With theses examples datas :
In entry, I have only the names of one entitie B (by example 'foo') and the name of one entity A ( by example 'A_b')
From a Repository class ( A repository class or B Repository class ? ), how can I get the entity B depending of only the strings 'foo' and 'A_b' entries ?
I must obtains in result the entity B with the id 1
I'm not a very strong doctrine DQL user.. And I'm looking for a proper way
Upvotes: 0
Views: 92
Reputation: 659
You can try this code:
public function getBByName($name)
{
$qb = $this->createQueryBuilder('A');
$qb->leftJoin('A.b', 'B');
$qb->where('B.name= :name');
$qb->setParameter('name', $name);
$query = $qb->getQuery();
$result = $query->getResult();
return $result;
}
Upvotes: 1