I am looking for an idea of creating a database with a table that is linked to several other tables. A concrete example is a site with comments on various things: people can comment on articles, or they can comment on photos or comment on people.
There seem to be two ways to present this:
1) join tables for each other table TABLES:
- articles
- articles_comments
- comments
- comments_people
- comments_photos
- people
- Photo
or 2)
- articles
- comments
- people
- Photo
and the comment table will have a type field, and item_id will refer to another table.
The first approach seems more “correct”, and it seems that we should not have problems using foreign key constraints, while the second approach has fewer tables and can be “simpler” in some respects, but we can use the FK constraints, since item_id may be associated with multiple FKs (AFAIK - using mysql innodb). Perhaps it would be nice if in our application there were no two tables with several relationships (comments, photos, etc.) and 5-10 tables requiring relationships.
I am looking for advice on which is best suited.
source share