I have a core data entity A that has a one-to-many relationship with entity B. Given a set of instances of entity B, how do I retrieve all instances of A that are NOT in a relationship with those instances of B? (I'm talking about IOS core data, if that matters).
Asked
Active
Viewed 755 times
1 Answers
2
NSSet *bEntities = a.b;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF NOT IN %@", bEntities];
NSManagedObjectContext *moc = ...;
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"B" inManagedObjectContext:moc]];
NSArray *result = [moc executeFetchRequest:fetchRequest];

omz
- 53,243
- 5
- 129
- 141