I am new to Core Data and I was wondering if I could get some advice on how to best lay out the following scenario with Core Data:
I have a Patient entity (and its corresponding NSManagedObject subclass). Each patient can have various diseases. Each disease is its own entity and managed object. In my Patient class I want to have an array filled with the diseases for that patient. However Core Data does not let you store an NSArray as an attribute.
What would be the best way to go about organizing this in Core Data?
I have thought of some options:
Use a transferable attribute in the Patient entity and store the array in this? Doesn't seem very clean though
Use an intermediate Controller entity between the Patient and the Diseases that could simulate some of the features of an array
I don't know if this is possible but perhaps do a fetch and only get those diseases that have a relationship with a certain patient?
Thank you for any help!
This is what relationships are for.
Patient has_many Diseases
Disease has_one Patient
Set these up and then you can to stuff like this:
patient.diseases //returns an NSSet (very much like an array)
Read more about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With