Let’s say we have 3 tables for contents, galleries, questions and one thable for comments like this:
**Contents**
--------------
ContentID | Title | Body
**Galleries**
--------------
GalleryID | Title | Rank
**Questions**
-------------
QuestionID | Title | Body | SendDate
**Comments**
------------
CommentID | Name | Body | ContentID | GalleryID | QuestionID
What is a standard way to connect Comments table to other 3 tables? Is it right way to use other three table’s foreign keys inside Comments table?
It’s right, but it’s better to have a Commentable Table, from which other 3 tables inherit. something like this:
All contents, galleries and questions , first should be inserted in Commentable, then in their own tables. So other tables will be like this:
And a comment will be associated with a commentable, so
and finally, if you need to specify if comment is from a gallery, question or content, you may put a field (i.e. Type) which shows the type of commentable. This way will reduce redundancy and has a more reasonable design.