我正在尝试使用具有不以 _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
有什么我想念的想法吗?