Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best solution for a comment table for multiple content types

I'm currently designing a comments table for a site I'm building. Users will be able to upload images, link videos and add audio files to the profile.

Each of these types of content must be commentable. Now I'm wondering what's the best approach to this.

My current options are:

  1. to have one big comments table and a link tables for every content type (comments_videos, ...) with comment_id and _id.

  2. to have comments separated by the type of content their for. So each type of content would have his own comments table with the comments for that type.

like image 441
KRTac Avatar asked Dec 13 '22 22:12

KRTac


1 Answers

I disagree with the accepted answer. How would you check the integrity of the data this way ? you can have corrupt ids if your application is not doing the right thing. Besides, you should never rely only on the application to assure the data integrity. Also, did you think how to cascade your deletes to the comment table when you remove any media ?

If you want to keep all the comments in one table you need two extra columns, one for the media id and one for the media type. Then you can write a trigger to enforce the integrity of your media(id,type) combination.

Can anyone say better ? -ken

like image 107
ken Avatar answered Jan 26 '23 16:01

ken