Article From:

Now we need to develop an article classification function. At present, there is a tentative three level classification. Considering the scalability of the classification, the table structure is designed as follows:


The question now is whether we need to save another hierarchical relationship, that is, to save the path, or to keep the depth of the tree.

Answer 0:

The article table:

id    name    type_id
Article ID name is classified as ID

Classification table:

id        name    parent_id
Classified ID classification name classification of parent ID

Another way is to pull the type_id out of a table in the article to make a relational table.

art_id     type_id    

Personal comparison recommends second ways to store the relationship separately and facilitate maintenance.

Leave a Reply

Your email address will not be published. Required fields are marked *