Is it considered a poor design to combine a contact list model and a nested set model?

I am working on creating a tree structure in MySQL and have been experimenting with various ways of representing data. However, no matter how I cut it, there are drawbacks.

The nested set model allows me to easily select whole tree branches - what do I need to do. However, it is not so easy to select immediate children from node.

The adjacency list model is great for getting immediate children, but not so good for returning entire branches of a tree.

I am wondering if there is anything particularly bad about building a tree structure as follows:

TABLE: Tree
    ID
    name
    lft
    rgt
    parentID

So, I have an adjacency list model and nested model sets all in one table. Thus, I can use either / or, depending on the circumstances from which I choose.

What are people's thoughts? It is allowed? (Peanut butter and chocolate together at last?) Or is this considered a poor design?

Thanks in advance,

+3
source share
2 answers

I highly recommend it myself. This is the style CakePHP uses for its tree structures, and as you pointed out, it gives you great flexibility. You just need to do a little more work to ensure the integrity of your tree, but it's worth it.

+1
source

No, this is a good design. At least in my opinion.

, , . , Adjacency List Model (, , ), parentIds Nested Set.

, ALM , .

, ...

, . , - . , Adjacency List, .

, , .

+1

Source: https://habr.com/ru/post/1734071/


All Articles