Open mhf-ir opened 5 years ago
Hello @mhf-ir!
fetchTree function just fetches the all (or limited by depth param) nodes from database. It returns all levels as you can see in your posted example. But it doesn't iterate over the data to build the tree like you expected.
The behaviour of fetchTree function is very simple to keep it fast -- simple interface for fetching data from database. Just imagine a table with 10k rows. Each loop will slow down the code a lot.
Unfortunately, no one function in the library builds the tree. I'll appreciate for MR (a separate function to build the hierarchy tree from 1-level array).
Tree algorithm in RDBM databases is limited use case not about 10K tree data. It's an antipattern for RDBMs databases. For many tree data correct you must use lazy load per node but during design many ting like Menu Category in typical use case this method will be helpful. Type orm implement it as official support problem of type orm is it's not support multi root and ordering nodes. https://github.com/typeorm/typeorm/blob/master/docs/tree-entities.md#working-with-tree-entities
I use fake data to generate about 10 root menu and about 100 menu.
I have simple test unit with fake data:
Sample output:
Desire output:
My full table json dump: https://paste.ubuntu.com/p/67sy2dhJkr/
Where is children of children of children.
i'v try depth 10 or any number but array return me one step of child.
Use case VueJS Menu: https://jsfiddle.net/chrisvfritz/pnqzspoe