[Nitro] Join tables

Rob Pitt rob at motionpath.com
Thu Nov 3 12:29:22 EST 2005

I have pushed a patch that does this to the motionpath darcs repo 
(depends on a couple of others relating to schema evolution also pushed 
by me today).

Unfortunately it is a little slower on startup as I could not think how 
to get around the problem that some of the tables to be joined could be 
missing when the join table is made without violating the "each og 
entitiy manages it's own store" paradigm there seems to be. This meant 
that sometimes you would have to start the program twice in order to 
have all the foreign key constraints added.

So, I came up with a solution. I added a 
OgManagedClass.resolve_remote_relations method that returns a list of 
all relations that point *to* OgManagedClass from within other classed 
managed by Og. Then, when making join tables, the constraints try to 
recursively be added to all other already known about classes that point 
at the current class (because now both tables will exist and the join 
table constraints can be made).

This works fine but is not really ideal. There is a new function called 
create_join_table_foreign_key_constraints(klass,info) that if someone 
came up of a better place to put it, could still be leveraged there instead.


George Moschovitis wrote:

>please send me the full patch with the foreign table constraints. This
>was something I planned to add for ages.
>On 11/3/05, Rob Pitt <rob at motionpath.com> wrote:
>>After updating to the latest nitro dev repository I ran delete_all on a
>>class that had a join table with itself. Once all records were deleted
>>there were numbers left over lying around in the join table. I never
>>noticed this before because I had patched the old version to add
>>PostgreSQL foreign key constraints on join tables. I will put these
>>constraints back into our version here which will take care of the
>>problem for us and possibly look at why that happens later but I thought
>>everyone else might like a heads up.
>>Nitro-general mailing list
>>Nitro-general at rubyforge.org
>Nitro-general mailing list
>Nitro-general at rubyforge.org

More information about the Nitro-general mailing list