数据库设计:复杂的投票系统
我有三个表 Feed
、Vote
和 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
event
和 feed
都可以由用户投票。 Vote
表跟踪谁对什么事情进行了投票,每个人只允许对事件
或feed
投票一次。所以这是我的问题:当我创建一个 event Y
时,我也会创建一个 feed
说 X 创建了 event Y
,它将出现在用户X
个人资料。如果有人对提要或事件 Y 进行投票,则两者对事件 Y
的投票以及对表示 X 创建了事件 Y
的 feed
应两者均为 1
。实现上述目标的最佳方法是什么?
b.此外,如果 X
已经对表示 X 创建了事件 Y
的 feed
进行了投票,那么他就无法对事件 Y
进行投票不再如此,反之亦然(因为每个用户只能对一个事件投票一次,在这种情况下,feed
和 event
实际上是同一件事)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此数据模型单独处理事件和提要,但可以记录父
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 CandidateWHERE ParentId is NULL
.