我想从 Rails 访问旧数据库模式。我有一个带有主键 OBJECT_ID 的表 NAGIOS_OBJECTS 和一个带有 HOST_OBJECT_ID 列的 NAGIOS_HOST_CHECKS 表。因此,我将关系定义如下:
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
但是,当调用 a_nagios_object.nagios_host_check 或 a_nagios_host_check.nagios_object 时,我总是得到 nil。
知道我的代码有什么问题吗?