post_consultant
및 consultant
인 Consultation
모델이 있습니다. post_consultant
과 consultant
은 모두 Employee
모델에 대한 참조입니다. 그래서 당신은 말할 수 있습니다 : 그 쓰기 가정하고 어떻게레일 연결 : 동일한 모델의 모델이 2 회 발생
모델
Class Consultation < ActiveRecord::Base
has_one :employee # for consultant
has_one :employee # for post_consultant
end
마이그레이션
create_table "consultations", force: :cascade do |t|
t.boolean "showed_up"
t.boolean "signed_up"
t.integer "client_id"
t.integer "consultant_id"
t.integer "post_consultant_id"
end
?
올바른 모델 :
class Consultation < ActiveRecord::Base
belongs_to :consultant, class_name: "Employee", foreign_key: "consultant_id"
belongs_to :post_consultant, class_name: "Employee", foreign_key: "post_consultant_id"
end
post_consultant 및 컨설턴트 모델입니까? – krishnar
post_consultant 및 컨설턴트의 외래 키는 무엇입니까? – krishnar
직원 만이 모델 –