0

Background: I am creating an application that allows users to comment on different object types. For simplicity sake, say I have Object A and Object B, both of which can be commented on. I want to store those comments in a database table. The data structure for comments for both objects is exactly the same, and the most common db query will be "get all comments for a specific Object A".

Question: Which of the following schemas would be most effective:

  1. A single table, Comments, with a column for "Type"
  2. Multiple tables, Comments_ObjectA and Comments_ObjectB, for each object type
  3. Something else I haven't considered

Example Usage

  1. Single table: "SELECT * FROM comment WHERE type="ObjectA" and id_object=123
  2. Multiple tables: "SELECT * FROM comment_objecta WHERE id_objecta=123"

Thank you for your help!

Scott Lieberman
  • 289
  • 2
  • 11
  • 1
    Definitely 1. And yes, question looks like a duplicate. – Erwin Brandstetter Sep 21 '12 at 19:20
  • @muistooshort - they are slightly different scenarios, though very similar. The question you referenced deals with commenting on multiple "pages" in a website, but where pages is the only object that needs commenting. In my example, I will have many instances of several different objects, all of which will require commenting. – Scott Lieberman Sep 22 '12 at 01:39
  • "Different pages" vs "different objects", there's little difference really, you have comment threads and things that have comment threads. I'd add a thread ID to your tables for your various commentable things and FK that to your thread, then comments are linked to threads similarly. If you really have no need for a separate "thread" concept then you have your "single table" solution. – mu is too short Sep 22 '12 at 01:54
  • @muistooshort thank you for your help, I am going to go with the thread concept. – Scott Lieberman Sep 25 '12 at 06:45

0 Answers0