jeremyevans/sequel — Issue #417: Associations with a key named "object_id" fail silently.
Author: hannesg
Created: 2012-01-10 13:59:48+00:00
State: open

Hi
Given following database:
Table Foo
id integer primary key;
Table Bar
id integer primary key;
object_id integer; # reference to Foo

Setting up the association works perfectly. Getting the correct Foo through Bar doesn't work. Getting all Bar for a Foo works.
However when it comes to eager loading Bar through Foo, sequel is acting weird. It does in fact query the Bar table but doesn't associate the objects, since it calls "object_id" on Bar to find the corresponding Foo. Changing the database-schema is not an option ( another software relies on it ) and it should not be necessary IMHO. Redefining object_id to match the column isn't a solution either.

My idea to solve this so far:
When adding column accessors, add additionally a method named __sequel_column_, which calls or retrieves the value for , whichever is more appropriate. Furthermore I added an instance method named column_value( name ) which uses __sequel_column_ if it exists. This method is then used instead of send in all associating-stuff.

Have a look at the first commit on it: https://github.com/hannesg/sequel/commit/db06d4832557fdb371ca53eab8c99c702db83f28

As far as I see, it broke nothing but the two additional examples work as expected.