开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜