【发布时间】:2013-12-24 20:41:08
【问题描述】:
我们有用户可以订阅的三种不同类型(用户、文章、评论)。 每种类型都有一个单独的表。我希望用户能够订阅另一个用户、文章或评论。
订阅表列:
id(integer, AI)
type('String, can be 'article', 'comment', 'user')
ref('integer', indicates the index key to an external table)
user_id('integer', foreign key to the users table)
因此,此行将是 id=101 的用户订阅了 id 为 99 的评论
1 | comment | 99 | 101
id=101 的用户也订阅了 id=88 的文章
1 | article | 88 | 101
你明白了。这是一个好的设计吗?
【问题讨论】:
-
这是一个很常见的设计。主要的错误是你不能在
ref上实现外键约束,因为它引用的表不同。