关于构建评论系统的建议
我是数据库设计的初学者,我想创建一个评论系统,能够回复用户评论并显示用户所做的所有评论。此外,将会有很多页面,每个页面都有一个用于评论的部分。
到目前为止,我已经提出了两种潜在的数据库设计来构建评论系统。第一个将有一个用于每个页面评论的表格和一个用于每个用户评论的表格。页面评论表将具有用于表链接目的的 user_id 和 page_id 字段。
第二个潜在的设计结构是拥有一个大型评论分区表,其中仅包含用于表链接的 comment_id 和 user_id 字段。我还没想好如何实现回复功能;在解决这个问题之前,我想了解哪种设计方法(如果有的话)可以有效地执行。
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用两张表:一张用于评论线程,另一张用于评论。评论线程看起来像这样:
和 comments:
然后通过向页表添加
comment_thread_id
列将线程附加到页面。拥有单独的不同注释线程可以让您在将来方便地附加访问控制或类似的扩展,它还允许您将注释线程附加到事物上。将评论线程附加到页面而不是相反,这样以后就可以轻松地将评论线程添加到系统中的其他对象。
I'd go with two tables: one for comment threads and another for the comments. The comment threads would look something like this:
and comments:
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.
使用它来存储页面的评论。
parent_id
是一条评论,是另一条评论的回复。对于页面上的评论,parent_id 将为零(无父评论),但对于回复,parent_id 将非零,并且它将是回复所属评论的 ID。例如,您将拥有这样的数据
您可以考虑使用
timestamp
、flaagged
、deleted
等字段来帮助您排序、排序、过滤、监控和软删除评论。您可以按页面、按用户、按父级进行分组。Use this to store comment for a page.
parent_id
is a comment that is a reply of another comment. For a comment on the page the parent_id will be zero (no parent comment), but for a reply the parent_id will be non-zero and it will be the ID of the comment which the reply belongs to.For example, you will have data like this
You may consider having
timestamp
,flagged
,deleted
etc fields that can help you in sorting, ordering, filtering, monitoring and soft-deleting a comment. You can group by page, by user, by parent.