【发布时间】:2013-12-12 16:14:11
【问题描述】:
我有一个我认为很简单的问题。我正在尝试过滤一些核心数据,其中我有一个父对象,该对象与子对象具有一对多关系,并且该子对象具有字符串 id。我想获取没有子对象具有特定 id 的所有父对象。
我尝试了!(ANY... LIKE) 以及!(ANY..==) 和NONE 与like 和== 和ALL children.id != otherid
我的查询看起来像:
NSFetchRequest* fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Parent"];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"NONE children.id LIKE %@",otherID];
[fetchRequest setPredicate: predicate];
NSError* error;
NSArray* allParents = [[DataManager context] executeFetchRequest:fetchRequest error:&error];
//sanity check the predicate
for (Parent* p in allParents) {
for (Child* c in p.children) {
if([c.id isEqualToString:otherID]){
NSLog(@"PREDICATE FAIL!");
}
}
}
我是否缺少 NSPredicate 的某些内容? CoreData 是否允许这种类型的过滤?更好的解决方案?
【问题讨论】:
-
Core Data NSPredicate with to-Many Relationship 的可能重复项 - 摘要:这是一个核心数据错误,您可以使用 SUBQUERY 作为解决方法。
标签: ios objective-c core-data nspredicate