PostgreSQL foreign key support for DataMapper
UPDATE: Please don't use this. It's way too hackish and certainly won't work against the current SVN trunk and definitely not against the git DataMapper repository. Wait for 1.0 or a bit later for foreign key support, but it will come.
First, there is no easy way to get it working by extending classes because of the inner workings of DM, particularly the Column#parse_options! method. I hear that things are getting re-jigged to use the Property class, and at that point it should get much easier to work things like this in.
Second, DM currently doesn't have migrations where order of operations can be controlled, so using foreign keys will most likely fail. For this to work migrations that support order, such as Crazy Migrations (tm) are required.
Third, there are no specs for the FK support.
And finally, here is the patch. Usage is rather simple:
property :name, :integer, :references => {
:reftable => "table",
:refcolumn => "referenced_column"
}
In addition, :match with values :full, :partial, and :simple as well as :on_delete and :on_update with values :restrict, :cascade, and :set_null can be specified.
Comments, flames, blames, opinions, and whatever else is welcome.