2011-10-18 4 views
1

사용자가 환자 또는 의사의 두 가지 유형이 될 수있는 응용 프로그램을 만들고 있습니다. 각 유형에는 고유 한 속성 세트가 있습니다.레일즈 : 모델 상속

공유 속성이 포함 된 사용자 모델을 만든 다음 사용자를 상속하는 Patient and Doctor 모델을 만들 수 있습니까?

답변

2

아니요,하지만 당신이 말한 것을 할 수 있습니다. 그런 다음 각 하위 클래스에 대해 특정 속성이 포함 된 모델에 연결을 추가하십시오. 그런 다음 delegate을 사용하면 자연스럽게 보이게 할 수 있습니다.

class User 
end 

class Doctor < User 
    has_one :doctor_profile 
    delegate :phd_in, :to => :doctor_profile 
end 

class Patient < User 
    has_one :patient_profile 
    delegate :symptoms, :to => :patient_profile 
end 

class DoctorProfile 
    # E.g. attributes: phd_in:string 
end 

class PatientProfile 
    # E.g. attributes: symptoms:text 
end 
+0

고마워요! 그것은 내 문제를 해결했다. – aperez