Reputation: 1752
I'm in a situation where I'm in a bit of doubt of whenever I should give a shared 'like' table or split it up into two different tables.
The application will show both videos/images in a 'wall' like manner, like Facebook and many other platforms do.
If the user has already liked an image or video the like button will be colored to show that the content has already been liked.
Video table
id title desc url src
------------------------------------
1 soms thing wwww .png
Image table
id title desc src
------------------------------
1 soms thing .jpg
Options 1 two tables
Vote table video
id video_fk user_fk voted
-----------------------------------------
1 1 1 2
Vote table image
id image_fk user_fk voted
-----------------------------------------
1 1 1 2
Options 2 1 table
Vote table shared (type_fk is identifying which type it is, 1 for image 2 for video)
id content_fk user_fk type_fk voted
-------------------------------------------------
1 1 1 2 2
The problem with 2 tables is when I have to lookup whenever or not a user has liked the content (when scrolling through the wall with many results) I will have to store the results in a multidimensional array with the id and an identifier to decide which content type it is (image or video).
What would you be the better way, or even a third way?
Upvotes: 0
Views: 48
Reputation: 1789
You should keep as little tables as possible, because then you reduce amount of requests and complexity of your code.
I would even go as far as to put both videos and images into the same table called 'content', seeing how almost all of your columns are the same.
Upvotes: 1