1

Say I'm building something like Facebook and I have many different entities in my database: Photos, Videos, Notes, Maps, Users, Groups, Songs, etc.. If I wanted the users to be able to comment on any of those entities, how should I model this in the database?

Conceptually, a Comment entity would relate to exactly one of the other entities, and the other entities would be related to zero, one or many comments.

My inclination is to have the other entities be sub-types of a parent "ContentType" entity, relate Comment to that, and somehow enforce through constraints a mutually exclusive relationship between the content types. But that feels a bit odd since there's no real relationship between the content types.

jl6
  • 6,110
  • 7
  • 35
  • 65
  • see http://stackoverflow.com/questions/3350489/how-to-design-the-relations-between-user-and-favoriteor-like-models-in-db/3352399#3352399 and http://stackoverflow.com/questions/4050784/defining-multiple-foreign-keys-in-one-table-to-many-tables/4051523#4051523 – Damir Sudarevic Jun 23 '12 at 21:29

1 Answers1

0

personally i would use a xml or txt for comments. if you want to use a database comment system you should connect comments to the multimedia one comment to one multimedia this way you would only filter the comments befor inserting them on the page and one comment to one user. comments being the center entety in the other way one user has more comments and more multimedia files.

Shawn
  • 228
  • 1
  • 4
  • 19