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 :)
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
Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems