I want to access a legacy database schema from Rails. I have one table NAGIOS_OBJECTS with a primary key OBJECT_ID and one table NAGIOS_HOST_CHECKS that refers to NAGIOS_OBJECTS with a column HOST_OBJECT_ID. I thus defined the relations as follows:
class NagiosObject < ActiveRecord::Base
has_one :nagios_host_check, :foreign_key => :host_object_id, :primary_key => :object_id
end
class NagiosHostCheck < ActiveRecord::Base
belongs_to :nagios_object, :foreign_key => :host_object_id, :primary_key => :object_id
end
However, when calling a_nagios_object.nagios_host_check or a_nagios_host_check.nagios_object, I always get nil.
Any idea what is wrong with my code?