Reputation: 7003
I'm not too sure how to word my question, but here it is.
Let's say I have multiple tables, dogs
, cats
, and birds
. Each of them have uploads
related to them. Each can have many, so I figured it would be best to be on its own table.
Which is a better approach?
uploads
table with for
taking the table (say dogs
), and for_id
referencing the id of that columnuploads
table with a columns dogs_id
, cats_id
, birds_id
, with one of them filled with the relative iduploads_dogs
, uploads_cats
and uploads_birds
Or maybe there is a better appraoch?
Thank you!
Upvotes: 0
Views: 62
Reputation: 180
You could use a single uploads table with a type id (birds = 1, cats = 2, etc.) and an object id column containing the ID of the cat/bird/dog. So when you want to find all uploads for a given cat:
SELECT * FROM uploads WHERE typeId = 2 AND objectId = [catId]
Upvotes: 2