in reply to Pseudo-Polymorphism

If the comments all have the same structure, why store them in different tables? Create a comments table and link that to each of the other four tables somehow. (I suspect you need a linking table to make the one-to-many relationship work, but that's pretty standard.)

Then all you need to do is use a templating system that allows you to use fragments or components and define a comment component and reuse that in your other templates.

Replies are listed 'Best First'.
Re^2: Pseudo-Polymorphism
by Spidy (Chaplain) on Sep 09, 2006 at 17:23 UTC
    That's pretty much the idea I had, but I was a bit confused about the linking table thing. What do you mean by that, and how would I do it?
      Don't you just need a field called "parent_type" (or whatever) in the "Comments" table? You'd then be able to query all the comments, all the comments associated with one of the four tables, and (in conjuction with "parent_id") all the comments associated with a specific item in one of the four tables.

      In SQL, I would generally handle that something like this:

      CREATE TABLE entity_ones ( id INTEGER, -- whatever goes in this table ); CREATE TABLE entity_twos ( id INTEGER, -- whatever goes in this table ); CREATE TABLE comments ( id INTEGER, author VARCHAR(128), content TEXT, -- etc ); CREATE TABLE entity_one_comments ( entity_one_id INTEGER NOT NULL REFERENCES entity_ones(id), comment_id INTEGER NOT NULL REFERENCES comments(id), PRIMARY KEY ( entity_one_id, comment_id ) ); CREATE TABLE entity_two_comments ( entity_two_id INTEGER NOT NULL REFERENCES entity_twos(id), comment_id INTEGER NOT NULL REFERENCES comments(id), PRIMARY KEY ( entity_two_id, comment_id ) );

      We're not surrounded, we're in a target-rich environment!