DB Design for Choosing One of Multiple Possible Foreign Tables

后端 未结 2 420
粉色の甜心
粉色の甜心 2021-01-21 23:08

Say if I have two or more vastly different objects that are each represented by a table in the DB. Call these Article, Book, and so on. Now say I want to add a commentening feat

2条回答
  •  遥遥无期
    2021-01-21 23:14

    I personally think your first option is best, but I'll throw this option in for style points:

    Comments have a natural structure to them. You have a first comment, maybe comments about a comment. It's a tree of comments really.

    What if you added one field to each object that points to the root of the comment tree. Then you can say, "Retrieve the comment tree for article 123.", and you could take the root and then construct the tree based off the one comment table.

    Note: I still like option 1 best. =)

提交回复
热议问题