我们假设我们有应用页面,帖子和事件。对于此应用程序的每个部分,我们希望有评论。现在让我们来看看我们的数据库表。
Page / Post / Event有很多注释,外键对象,object_id
comments table +-------------+-------------+-------------+-------------+ | id | object | object_id | text | ========================================================= | 1 | Page | 1 | Comment 1 | +-------------+-------------+-------------+-------------+ | 2 | Post | 1 | Comment 2 | +-------------+-------------+-------------+-------------+ | 3 | Event | 1 | Comment 3 | +-------------+-------------+-------------+-------------+
页面(帖子,事件)有很多页面注释,外键是page_id
page_comments table +-------------+-------------+-------------+ | id | page_id | text | =========================================== | 1 | 1 | Comment 1 | +-------------+-------------+-------------+ post_comments table +-------------+-------------+-------------+ | id | post_id | text | =========================================== | 1 | 1 | Comment 2 | +-------------+-------------+-------------+ event_comments table +-------------+-------------+-------------+ | id | event_id | text | =========================================== | 1 | 1 | Comment 3 | +-------------+-------------+-------------+
我使用了具体的例子,但这可以适用于任何其他1:N表格,甚至适用于M:N(标签),但对于简单的展示,这应该是好的。
我们应该讨论
初步想法