您想对产品、用户、评论等进行 cmet 吗?
或者找到评论所指的产品、用户、评论等?
对于前者,我会使用表格将事物与它们的 cmets 关联起来:
create table join_products_comments (
product_id int (unique, i.e., one thread of comments per product),
comment_thread_id int
);
create table join_users_comments (
user_id int (unique, i.e., one thread of comments per user),
comment_thread_id int
);
comment_thread 只是对每个评论引用的线程的引用:
create table comment_threads (
thread_id int (PK),
thread_name nvarchar2(256),
created datetime
);
create table comments (
comment_id int (PK),
comment_thread_id int (FK),
parent_comment_id int (FK),
user_id int (FK), -- person who posted the comment
comment text,
created datetime
);
因此,系统中的每个可评论实体都会有一个连接表和一个评论线程,等待热切的用户添加 cmets。或者,您可以直接链接到根评论,而不使用这种间接方式。