Suppose you had a data model that looks like this:
/-----------------------\ /-----------------------\
| Patient | | Medication |
|-----------------------| |-----------------------|
| firstName | | startOn |
| lastName | | endOn |
|-----------------------| |-----------------------|
| medications | <<-\ | |
| | \->> | patients |
\-----------------------/ \-----------------------/
Thus, there is a many-to-many relationship: patients have many drugs, and medicines have many patients.
Given an object Patient, how do you get related Medicationto the latter endOn? (assumption: the patient does not have more than one medicine that ends on the same date), that is:
Patient *patientZero = ...;
Medication *mostRecentMed = [patientZero mostRecentlyCompletedMedication];
How to implement the method mostRecentlyCompletedMedication?
Thank!
source
share