jeremyevans/sequel — Issue #403: Error when model, relationship, and fk are all the same name
Author: abedra
Created: 2011-12-01 14:32:45+00:00
State: open

I am working with a legacy database that has some baggage. It has a users table with a school fk. The field name on the table is school. There is also a schools table that holds the information. The sequel model looks something like this...

class User < Sequel::Model
many_to_one :school, :key => :school
end

With this in place, along with the one_to_many on the School model, the following error occurs:

NoMethodError: undefined method `pk' for 1:Fixnum

If I change the relationship name, everything works:

many_to_one :foo, :class => :school, :key => :school