数据库设计:复杂的投票系统

发布于 2024-10-07 22:08:39 字数 991 浏览 0 评论 0原文

我有三个表 FeedVoteEvent

Feed
+id
+content
+voteCount  --> hold the number of votes on this feed

Vote
+id
+feedId --> FK to id in Feed
+eventId --> FK to id in Event

Event
+id
+name
+voteCount --> hold the number of votes on this event

eventfeed 都可以由用户投票。 Vote 表跟踪谁对什么事情进行了投票,每个人只允许对事件feed 投票一次。所以这是我的问题:当我创建一个 event Y 时,我也会创建一个 feedX 创建了 event Y ,它将出现在用户X个人资料。如果有人对提要事件 Y 进行投票,则两者事件 Y 的投票以及对表示 X 创建了事件 Yfeed两者均为 1

。实现上述目标的最佳方法是什么?

b.此外,如果 X 已经对表示 X 创建了事件 Yfeed 进行了投票,那么他就无法对事件 Y 进行投票不再如此,反之亦然(因为每个用户只能对一个事件投票一次,在这种情况下,feedevent 实际上是同一件事)

I have three tables Feed, Vote and Event.

Feed
+id
+content
+voteCount  --> hold the number of votes on this feed

Vote
+id
+feedId --> FK to id in Feed
+eventId --> FK to id in Event

Event
+id
+name
+voteCount --> hold the number of votes on this event

Both event and feed can be up-voted by user. The Vote table keep track of who has been voting on what since, each only allow to vote once on an event or feed. So here is my problem: when I create an event Y, I will aslo create a feed say X created event Y which will appear on the user X profile. If someone vote on either the feed or event Y, the vote of both the event Y and the vote of the feed that said X created event Y should both be 1.

a. What is the best way to achieve the above?

b. Also if X already vote on the feed that said X created event Y, then he cant vote on event Y anymore and vice versa (since each user can only vote once on an event, and in this case the feed and the event really is the same thing)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-10-14 22:08:39

此数据模型单独处理事件和提要,但可以记录父Candidate。组合投票的特殊 (?) 情况可以在应用程序层中处理,方法是仅允许对根候选人WHERE ParentId is NULL进行投票。

替代文本

This data-model treats events and feeds separately, but can record the parent Candidate. The special (?) case of combined votes can be handled in the application layer, by allowing votes only on the root Candidate WHERE ParentId is NULL.

alt text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文