in reply to Re: Pseudo-Polymorphism
in thread Pseudo-Polymorphism

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?

Replies are listed 'Best First'.
Re^3: Pseudo-Polymorphism
by ikegami (Patriarch) on Sep 09, 2006 at 18:37 UTC
    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.
Re^3: Pseudo-Polymorphism
by jasonk (Parson) on Sep 10, 2006 at 02:22 UTC

    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!