Make
For any master data restriction that runs on more than one managed entity at once, you want to look at an implementation:
- (BOOL)validateForDelete:(NSError **)error - (BOOL)validateForInsert:(NSError **)error - (BOOL)validateForUpdate:(NSError **)error
(I usually have kernel data, make .h and .m files for an object, and then create my own category for such things, so I donβt have much work if I changed the object a bit)
If you have something you just need to make sure the values ββin one managed entity are correct, you can use -validate<Key>:error:
To do what you are looking for, I would do validityForInsert / validateForUpdate EventItems call a generic method (possibly validateUniqueOrder). In this method, I would use the relation of EventItems to the event, and then retrieve all the EventItems associated with the event, and then check for uniqueness. I have rather small sets of relations, so I didnβt worry about anything, but if you have a lot of event elements related to the given events, you can look at the setPropertiesToFetch NSFetchRequests method. Or maybe you can find a query that can directly look for duplicate values ββ(I never could, so if you do, answer here to enlighten me).
source share