具有多个对多条件的 Core-Data NSPredicate
大家好,
我有以下核心数据数据库:(
不幸的是,由于垃圾邮件预防,我无法嵌入图像!)
数据库模型图像:http://snapplr.com/eqx9
我正在尝试创建一个 fetchRequest,它会获取其 fcCollection.fcSets.trainingSet
属性是我的代码中的对象的所有 FC 对象,但是不在trainingSet.memorizationSession.mistakeFCs 中。我想在 NSFetchedResultsController
中使用它。
我尝试了很多不同的东西,但它们都不起作用(不幸的是我没有保存我尝试过的东西,所以我无法发布)。 但我尝试过SUBQUERIES等等。我的最后一个方法如下:
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName: kFCMistakeEntityName
inManagedObjectContext: self.managedObjectContext];
[fetchRequest setEntity: entity];
NSPredicate *subPredicate = [NSPredicate predicateWithFormat:
@"memorizationSession.trainingSet == %@", _trainingSet];
[fetchRequest setPredicate: subPredicate];
NSArray *mistakeFCs = [self.managedObjectContext executeFetchRequest:fetchRequest error: nil];
predicate = [NSPredicate predicateWithFormat:
@"ANY fcCollection.fcSets.trainingSet == %@ && NOT mistakeFC in %@", _trainingSet, mistakeFCs];
不幸的是我收到此错误:
2011-05-18 22:26:55.643 testApp[9464:207] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“未实现谓词的 SQL 生成:(mistakeFC IN { FCM 错误:空 FC;正确 FC:0,FC 错误:55;FCM 错误:空 FC;正确 FC:3,FC 错误:空 FC;正确 FC:9,FCM 错误:空 FC;
;预先感谢您的帮助!
问候,金
Helo guys,
I have the following core-data database:
(Unfortunately I cannot embed the image, because of the spam prevention!)
Data base model image: http://snapplr.com/eqx9
I am trying to create a fetchRequest, which fetches all FC objects whose fcCollection.fcSets.trainingSet
property is an object in my code BUT are not in trainingSet.memorizationSession.mistakeFCs
. I want to use it in NSFetchedResultsController
.
I have tried so many different things and they all didnt work (Unfortunately I didnt save what I tried, so I cannot post).
But I have tried SUBQUERIES and so on. My last approach is the following:
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName: kFCMistakeEntityName
inManagedObjectContext: self.managedObjectContext];
[fetchRequest setEntity: entity];
NSPredicate *subPredicate = [NSPredicate predicateWithFormat:
@"memorizationSession.trainingSet == %@", _trainingSet];
[fetchRequest setPredicate: subPredicate];
NSArray *mistakeFCs = [self.managedObjectContext executeFetchRequest:fetchRequest error: nil];
predicate = [NSPredicate predicateWithFormat:
@"ANY fcCollection.fcSets.trainingSet == %@ && NOT mistakeFC in %@", _trainingSet, mistakeFCs];
Unfortunately I am getting this error:
2011-05-18 22:26:55.643 testApp[9464:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (mistakeFC IN {FCMistake: empty FC; correctFC: 0, FCMistake: 55; correctFC: 9, FCMistake: empty FC; correctFC: 3, FCMistake: empty FC; correctFC: 9, FCMistake: empty FC; correctFC: 4})'
This must be possible somehow! Thanks in advance for helping!
Greetings, Kim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自谓词编程指南:
因此,如果您使用 SQL 数据存储,则只能在谓词中表示一种一对多关系。如果您更改为其他持久性存储,则似乎意味着此特定限制已解除。
From the Predicate Programming Guide:
so if you are using the SQL datastore you can only represent one one-to-many relationship in your predicates. If you change to some other persistence store it seems to imply that this particular restriction is lifted.