Suppose you have these tables: RestaurantChains
, Restaurants
, MenuItems
- with the obvious relations between them. Now, you have tables Comments
and Ratings
, which store the customer comments/ratings about chains, restaurants and menu items. What would be the best way to link these tables? The obvious solutions could be:
- Use columns
OwnerType
andOwnerID
in the tablesComments
andRatings
, but now I can't add foreign keys to link comments/ratings with the objects they are ment for - Create separate tables of
Comments
andRatings
for each table, e.g.MenuItemRatings
,MenuItemComments
etc. This solution has the advantage that all the correct foreign keys are present and has the obvious disadavantage of having lots and lots of tables with basically the same structure.
So, which solution works better? Or is there even a better solution that I don't know about?