I searched the internet and found a few solutions, but none of them worked in ORM Doctrine, it was a bug.
I want to achieve the effect as below.
Result:
Table schema:
There are two ways to achieve the desired effect, and neither of them is available in standard DQL with the schema provided.
First, you might choose to use a recursive SQL query to get the proper ordering in each subtree. You'll need to map the results of the native query to be able to work on ORM objects again.
The other way is to add an extra column to the table, and store the full path (or any global positioning information) of each node. After this, a quick ORDER BY
works flawlessly even in DQL. You might find the tree behavior extension handy to automate most parts.