Re: Polymorphic delete help needed

From: Perry Smith <pedz(at)easesoftware(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Polymorphic delete help needed
Date: 2007-07-06 13:39:50
Message-ID: 30C594EE-9DC2-4B50-8991-16E4739677AA@easesoftware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jul 6, 2007, at 8:01 AM, David Fetter wrote:

> On Thu, Jul 05, 2007 at 09:56:12PM -0500, Perry Smith wrote:
>> I am doing a project using Ruby On Rails with PostgreSQL as the
>> database. I have not seen the term polymorphic used with databases
>> except with Rails so I will quickly describe it.
>
> You have now :)
>
> http://archives.postgresql.org/sfpug/2005-04/msg00022.php
>
>> Instead of holding just an id as a foreign key, the record holds a
>> "type" field which is a string and an id. The string is the name of
>> the table to which the id applies. (That is slightly simplified).
>
> This is brittle by nature. The above link sketches out a way to make
> it stable. If you have questions, ask :)
>
>> The first problem
>
> of many ;)
>
> [other stuff snipped]
>
>> that creates is it makes it hard to do a constraint
>> on the name/id pair.
>
> Let PostgreSQL work *for* you instead of picking a fight with it and
> then piling on heaps of unnecessary code.

I really want to follow this particular edict. Rails makes it easy
to put the checking up in Rails but, I assume that if the interface
between PostgreSQL and one of its languages like "SQL" or Python,
etc is an inch thick, then the interface between Rails and PostgreSQL
would be 12 inches thick.

You and PFC I think are on a similar track. I need to figure out how
to get Rails to do it this way. I was thinking just teach Rails
about the flex_key view and then add rules for insert, delete, set.
That is where I start to feel intimidated. It doesn't look hard but
I've just never done it.

The other place where my knowledge is lacking is when I get a 'thing'
from the database into Rails, making it an instance of a particular
class. That can't be too hard though.

Let me work on this over the weekend. This is not a "for work"
project. I really appreciate the help.

Perry
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-07-06 13:49:28 Re: Nested Transactions in PL/pgSQL
Previous Message PFC 2007-07-06 13:23:35 Re: Polymorphic delete help needed