Scenario:
Let's say I have an object named Author that has a to-many relationship called books to a Book object (the inverse relationship of Author ). If I have an existing collection of Author objects, I want a crash regarding books for all of them in a single fetch request.
the code
This is what I have tried so far:
NSArray *authors = ... // array of `Author` objects NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Book"]; fetchRequest.returnsObjectsAsFaults = NO; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"author IN %@", authors];
The execution of this query to the selection does not lead to the fact that the books relation of objects in the authors array is erroneous (checked by logging).
I also tried doing the fetch request differently:
NSArray *authors = ... // array of `Author` objects NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Author"]; fetchRequest.returnsObjectsAsFaults = NO; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", authors]; fetchRequest.relationshipKeypathsForPrefetching = @[@"books"];
It also does not cause crashes. What is a suitable way to do this?
objective-c core-data nsfetchrequest
indragie
source share