开发者

Database Design: Complex Voting System

开发者 https://www.devze.com 2023-01-30 18:25 出处:网络
I have three tables Feed, Vote and Event. Feed +id +content +voteCount--> hold the number of votes on this feed

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 eith开发者_JAVA技巧er 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)


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.

Database Design: Complex Voting System

0

精彩评论

暂无评论...
验证码 换一张
取 消