Answer the question
In order to leave comments, you need to log in
How to make a nested query in Doctrine DQL?
Good afternoon.
You need a query like this:
SELECT name,
(SELECT id
FROM tree t2
WHERE t2.left_key < t1.left_key AND t2.right_key > t1.right_key
ORDER BY t2.right_key-t1.right_key ASC LIMIT 1) AS parent
FROM tree t1
WHERE t1.left_key >= 1 AND t1.right_key <= 6
ORDER BY right_key-left_key DESC
Answer the question
In order to leave comments, you need to log in
Perhaps you should pay attention to the ready-made implementation of trees for Doctrine? There is also an integration for this package in Symfony. This will allow you not to reinvent the wheel, but to use a ready-made, proven and very popular solution, freeing up time from writing and supporting your implementation for other tasks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question