From Symfony 4, I have a ManyToOne relation between entities A and B (several B for only one A). I want select all id's A rows only if an 'child' B have the value 1 in its specificfield.
The table 'A' :
---
id
---
0
1
2
The table 'B' :
----------------------------------
id parent_id specificfield
----------------------------------
0 1 1
1 1 0
2 2 0
Result expected :
---
id
---
1
// because, only the A row with the id 1 have at least one 'child' in the table B with the specificfield set to 1
I tried build a query like this :
$res = $this->em->createQueryBuilder()
->select('A.id')
->from(Parent::class,'A')
->innerJoin(Child::class,'B',Join::ON,"A.id = B.parent_id")
->where('B.specificfield = 1')
->distinct()
->getQuery()
->getResult();
But I get the error : "Expected end of string, got 'ON'" .
The sql query equivalent works in my phpmyadmin ..
SELECT DISTINCT A.id
FROM parent A
INNER JOIN child B ON A.id = B.parent_id
WHERE e.specificfield = 1
I don't see where is my mistake in my dql query ..