I’m trying to replicate SE’s voting system. User’s on my website should only be able to vote on posts one time, then they are locked in. I currently have two tables, users and posts.
How should I store information on which posts a user has voted on? I was thinking of having a column in posts which would store the uids of users which have voted on it. Another idea would have a column in users with the ids of the posts he/she has voted on.
How should I do this? I want to take scalability into account and easy of determining whether or not the vote is valid.
Create another table to store information from the
usersandpoststables:With this approach:
Unless you store the values as delimited values (to fit in one cell) or JSON, you’ll end up with many rows for just one post. But then, that’s a bad approach to start with.
Stick with creating a new table which contains the relationship determining “voting”. The table is simple enough to check: