Doctrine 2, DQL Correlated subquery in LEFT JOIN

1.1k views Asked by At

Is it possible to translate this SQL to DQL:

SELECT project.*, task.*
FROM `project` 
LEFT JOIN (
    SELECT * FROM task 
    WHERE (task.title LIKE '%add%' OR task.description LIKE '%add%' )
) task ON project.id = task.project_id
WHERE project.id = 50

I need Project to be returned even if there are no tasks found.

My initial DQL was:

SELECT p, t FROM MyBundle:Project p 
LEFT JOIN p.tasks t
WHERE p.id = :id AND (t.title LIKE :title OR t.description LIKE :description)
ORDER BY t.id DESC

But this will return null if no task is found.

0

There are 0 answers