Reputation: 1416
I have a users database and a comments database on a website, and I want to give each user the ability to have a list of favorite comments, and I don't know exactly how to implement this.
Should I create a new table for each user containing the IDs of his/hers favorite comments or is there a better approach?
Upvotes: 0
Views: 1249
Reputation: 4606
I would use three tables :
users
table, containing every users, including their personal informations, etc ;comments
table, containing every comments ;favorites
table, containing the id
of the row, the id
of the user and the id
of the comment.I did not name each table well, you should think more about the tables' names (e.g: favorites
is a bad name).
Upvotes: 1
Reputation: 73011
A common, normalized approach would be a many to many relationship.
The schema for such a table, at a minimum, would be:
user_id
comment_id
Where user_id
and comment_id
are foreign keys to the users
and comments
table, respectively.
Upvotes: 3