_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: モデル Department で関連付け :departments_locales が見つかりませんでした
私が見逃しているアイデアはありますか?