1

I am creating an aplication where users can be of two types: a patient or a doctor. Each type has its own set of attributes.

Is it possible to create a User model that contains the shared attributes, and then create a Patient and Doctor models that inherit from User ?

0

1 Answer 1

2

No, but you can do what you said, and then for each subclass add an association to a model that contains the specific attributes. Then you can use delegate to make things seem seamless.

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.