Я пытаюсь использовать таблицу соединений с внешним ключом, который не заканчивается на _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: Не удалось найти ассоциацию: департаменты_locales в модели Department
Есть идеи, что мне не хватает?