Core Data - Fetch all objects NOT in a relationship
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 IO开发者_如何学编程S core data, if that matters).
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];
精彩评论