MODELS
Patient:
Description:
Should have only 1 Referrer
Association:
has_and_belongs_to_many :referrer
Referrer:
Description:
Contains all the types of referrers such as, but is not limited to:
- Partners
- etc.
Association:
has_and_belongs_to_many :referrer
Referrer Type (a new model I think I should add):
Details of referrers are here, such as name of the website that lead the patient to go to this hospital, or name of the partner that suggested the hospital to the patient.
WORKFLOW & EXPLANATIONS
In a form, the hospital employee takes the details of the patient. One of the details is the referrer -- the entity that referred the patient to this hospital. The referrer is rendered as a dropdown listbox.
I made the association between Patient-Referrer as HABTM because of the following reasons:
- The Referrer model will also be used by another model aside from Patient.
- The Referrer model has its own scaffold where an admin can add/remove referrers.
REQUIREMENT (THE PROBLEM)
Every time the dropdown box's value is "Partner", there should be a field to input the name of that entity. That is where the 3rd model will come in. The 3rd model will contain the:
- name of the partner
- a reference to the Referrer model's record named "Partner"
- a reference to the Patient record.
With the 3rd model now in play, how will I be able to insert new referrer details for each patient per referrer, and making it cascadable, in a sense that when I delete the Patient, the Referrer detail will be deleted, but the Referrer will still be kept untouched, the rails way.