I have a database where I have comments, votes, art galleries, images, etc... For good examples, art galleries and pictures could be said utilizing the same form, then I'll store it in one table, comment.

I am wondering wouldso would store this kind information within the comment table? Utilizing a ENUM type, an overseas key against a kind table, hardcoded on place, etc.. ?

You will find most likely a few ways you can design this while retaining foreign secrets.

The very first is to essentially possess a comment table for every type have them separate. For every comment possess a foreign answer to parents gallery or image, with respect to the table.

The second reason is to possess a table (say commentables) that consists of common data for anything that's commentable. Each gallery or image includes a foreign answer to a distinctive corresponding row in commentables. Each row within the comment table includes a foreign answer to the commentable, together with the written text from the comment, date, etc.

You'll most likely find this helpful anyway since you'll eventually want metadata for that collection of comments in general...at the.grams. to specify whether leaving comments is disabled, enabled for buddies only, or enabled for everyone.

Edit Option 3 is much like option 1 but rather than getting full separate comment tables for every commentable type, simply have separate associative tables for every commentable type.

|comments|    |gallery_comments|   |image_comments |
 --------      ----------------     ---------------
|id  (pk)|    |comment_id  (fk)|   |comment_id (fk)|
|text    |    |gallery_id  (fk)|   |image_id   (fk)|
|date    |     ----------------     ---------------
|author  |
 --------

A lot better than option 1 for me.

Foreign key against a kind table would get my election. Something similar to this:

alt text