【发布时间】:2011-02-04 02:01:03
【问题描述】:
我正在尝试使用具有不以 _id 结尾并指向非 id 主键的外键的连接表。这就是我所拥有的。
我的连接表如下所示:
[DepatmentsLocales] (
department_id
locale_code
display_name
)
这是我的模型:
class Locale < ActiveRecord::Base
has_many :departments, :through => :departments_locales
end
class Department < ActiveRecord::Base
has_many :locales, :through => :departments_locales
end
class DepartmentLocale < ActiveRecord::Base
belongs_to :department
belongs_to :locale, :foreign_key => :locale_code, :primary_key => :code
end
Rails 仍然找不到关联。当我调用 department.locales 时,我得到:
ActiveRecord::HasManyThroughAssociationNotFoundError: 在模型部门中找不到关联:departments_locales
任何想法我错过了什么?
【问题讨论】: