Basically I want to execute this mysql query with doctrine:
select distinct user_id from work_hour where project_id = ?;
But I don't know how I can do this with pretty Doctrine code. Is it possible to make it look like the following pseudo code or do I have to use the query builder?:
$project = new Project();
...
$entities = $em->getRepository('AppBundle:WorkHour')
->findByProject($project)->selectUser()->distinct();
Where $entities is an array of User objects
WorkHour and Project have a ManyToOne relation
WorkHour and User have a ManyToOne relation
You'll need to use a
QueryBuilder
for that, but that would still be quite a "pretty Doctrine code" and would still look quite like your pseudo-code.Something like this should work: