I just started working with Core Data this week. The big question!
Relations:
Because one patient can have many control points, the Patient to Checkpoint relationship is the One to Many relationship. The concept of “feedback” is basically this: you have a relationship going one way (Patient to Checkpoint) - now go and look at it from the back, at the control point. The control point can be applied to only one patient. Therefore, the Checkpoint to Patient relationship is a One to One relationship.
Inverse relationship:
To handle the feedback, simply create each relationship, ignoring the opposite. Then, after you have a relation to each object, go ahead and define the opposite as a relation to another object.
In other words, a relation points to another object or group of entities. An inverse relationship indicates a relationship to another object.
Delete rules:
As for the removal rules, this is pretty simple. When trying to remove a patient who has milestones ...
- Deny: These kernels will not allow you to delete a patient.
- Cascade: Core Data will remove Entity (Patient), and also cascade through relationships and delete these objects. (In other words, Core Data will also remove checkpoint objects.)
- Nullify: Core Data will delete the patient, but the relationship will be deleted first. The control point will remain untouched.
The Patient object may require either a failure or a cascade, depending on how you want to manage your data. Based on your use case, you probably do not want to reset the value, since the control points depend on the patient’s objects.
You want to invalidate the control point, because Cascade will not allow you to delete the control point without deleting the entire patient, and Deny will effectively force it.
source share