本文介绍了设计评论表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想创建一个评论系统,其中评论可能有父母也是评论,但我也希望他们可能有父母可能是别的,如用户或产品(即我想要能够评论产品,用户,其他评论或几乎任何资源)

Basically I want to create a comment system where comments may have parents that are also comments BUT I would also like them to potentially have parents that may be something else, such as users or products (ie, I want to be able to comment on products, users, other comments, or practically any resource)

我该怎么做?

当前表格:

标签,产品,用户,评论

tags, products, users, comments

编辑 - 这将是一个有点高的流量网站,所以我不能做各种疯狂: - )

edit - this would be for a somewhat high traffic site, so I can't have it doing all kinds of craziness :-)

推荐答案

你想对产品发表评论,用户,评论等?
或查找评论是指的产品,用户,评论等?

Do you want to have comments on products, users, reviews, etc? Or find the products, users, reviews, etc, that a comment is referring to?

对于前者,我将有表格将其与他们的评论:

For the former, I would have tables to associate things with their comments:

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只是引用每个注释引用的线程:

Where a comment_thread is just a reference to a thread that every comment references:

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
);

所以系统中每个可注释的实体都会有一个连接表,一个comment_thread只是等待着急切的用户添加评论。或者你可以直接链接到一个根注释,而不用间接。

So every commentable entity in the system would have a join table and one comment_thread just waiting for eager users to add comments to. Or you could just link to a root comment instead and do without that indirection.

这篇关于设计评论表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:32