Re: many to one of many modeling question - Mailing list pgsql-general

From Kevin Hunter
Subject Re: many to one of many modeling question
Date
Msg-id 47827E4A.2030309@earlham.edu
Whole thread Raw
In response to Re: many to one of many modeling question  (brian <brian@zijn-digital.com>)
Responses Re: many to one of many modeling question
Re: many to one of many modeling question
List pgsql-general
At 2:09p -0500 on 07 Jan 2008, brian wrote:
> Kevin Hunter wrote:
>> Is there a clever/clean way of having the comments foreign key into
>> the multiple tables?
>
> If, by object, you mean that you have several tables, each row of which
> should be associated with one or more comments, the best way would be to
> create join tables for each of those tables:

:-( Yeah this is one method.  I was hoping for something cleaner though.
  Something along the lines of

CREATE TABLE o_1 ( id SERIAL ... );
CREATE TABLE o_2 ( id SERIAL ... );
CREATE TABLE o_3 ( id SERIAL ... );
CREATE TABLE comments (
    id SERIAL,
    obj_id INTEGER ...
    FOREIGN KEY (obj_id) REFERENCES ONE OF o_1(id), o_2(id), o_3(id)
);

This obviously won't syntactically work, but you perhaps get the drift ...

> Out of curiosity, is this for a CakePHP app?

Nope.  This is for a customers private project.  Sorry!  :-)

Kevin

pgsql-general by date:

Previous
From: Greg Smith
Date:
Subject: Re: calculating shared data memory space
Next
From: Greg Smith
Date:
Subject: Re: Performance problem. Could it be related to 8.3-beta4?