构建评论系统的建议 [英] Advice on Structuring a Comment System

查看:186
本文介绍了构建评论系统的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是数据库设计的初学者,我想创建一个评论系统,能够回复用户评论,并显示用户做出的所有评论。此外,将有许多页面,每个都有一个评论部分。

I am a beginner at database design and I would like to create a comment system with the ability to reply to user comments and to display potentially all comments a user has made. Furthermore, there will be many pages that will each have a section for commenting.

到目前为止,我已经提出了两种潜在的数据库设计来构建评论系统。第一个将有一个表的每个页面的评论和表的每个用户的意见。页面注释表将具有用于表链接目的的user_id和page_id字段。

So far I have come up with two potential database designs to structure the comment system. The first will have a table for each pages' comments and a table for each users' comments. The page comment table will have user_id and page_id fields for table linking purposes.

第二个潜在的设计结构是有一个大的分区的注释表,只有comment_id和user_id字段用于表链接。我还没有想过如何处理回复功能;我想获得一些输入,在我解决这个问题之前,哪个设计方法(如果有的话)会有效地执行。谢谢!

The second potential design structure is to have one large partitioned table of comments that just has comment_id and user_id fields for table linking. I haven't thought about how to approach the reply feature yet; I wanted to get some input on which design approach, if any, would perform efficiently before I tackled that problem. Thank you!

推荐答案

我会用两个表:一个用于注释线程,另一个用于注释。注释线程看起来像这样:

I'd go with two tables: one for comment threads and another for the comments. The comment threads would look something like this:

id
/* Other bookkeeping things like created time and such */

和注释:

id
thread_id
user_id
comment
parent_id
/* Other bookkeeping stuff */

然后通过向页表中添加 comment_thread_id 列,将线程附加到页面。

Then attach the thread to the page by adding a comment_thread_id column to the page table.

有一个单独的注释线程给你一个方便的地方附加访问控制或类似的扩展在未来,它也允许你附加注释线程的东西。将注释线程附加到页面而不是其他方式,使得以后很容易向您系统中的其他对象添加注释线程。

Having a separate distinct comment thread gives you a convenient place to attach access control or similar extensions in the future, it also allows you to attach comment threads to things. Attaching the comment threads to the page rather than the other way around makes it easy to add comment threads to other objects in your system later on.

这篇关于构建评论系统的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆