0
_id로 끝나지 않는 외래 키와 조인 테이블을 사용하려고합니다. 비 ID 기본 키를 가리 킵니다. 여기에 내가 가진 것이있다. 테이블을 조인 내Rails 3 - _id 열이 아닌 테이블 조인
그래서 다음과 같습니다
아직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
, 레일이 연결을 찾을 수 없습니다 : 여기
[DepatmentsLocales] (
department_id
locale_code
display_name
)
내 모델입니다. department.locales를 호출하면 다음과 같은 메시지가 나타납니다.
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :departments_locales in model Department
아이디어가 없습니다.
입력 해 주셔서 감사합니다. 기능적으로는 작동하지만 깨끗한 것은 아닙니다. "ID"를 조인 테이블의 기본 키로 사용하지 않고 department_locales를 엔터티로 사용하지 않으려합니다. 제 경우에는 SQL을 사용하여 가져올 것이라고 생각합니다. –
모델에서 primary_key 메소드를 사용하여 원하는대로 DepartmentLocale 모델 테이블의 기본 키를 설정할 수 있습니다. 당신이 원하는대로 모든 일을하기를 바랍니다! 행운을 빕니다 –