Consider a site where a user can rate games. The ratings available are: None, Liked, or Disliked. The code will keep track of the ratings just fine. The current problem is a user can rate a game and just keep re-rating it.
How would a SQL table look if I wanted to store a user’s rating for a certain game? Duplicate ratings for each user/game shouldn’t be allowed.
You can use the following tables:
where
user_idandgame_idrefer to user and game. They both form thePRIMARY KEY, so the model does not support a user rating more than once.ratingcontains-1,0, or+1and can be summed to get the score of a game.