简体   繁体   中英

Parent-Child order ORM DOCTRINE

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM