具有多个对多条件的 Core-Data NSPredicate

发布于 2024-11-08 01:08:48 字数 1612 浏览 1 评论 0原文

大家好,

我有以下核心数据数据库:(

不幸的是,由于垃圾邮件预防,我无法嵌入图像!)

数据库模型图像: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-11-15 01:08:48

来自谓词编程指南:

Core Data SQL 存储仅支持
每个查询一对多操作;
因此在发送到的任何谓词中
SQL存储,可能只有一个
运算符(以及该运算符的一个实例
运算符)来自 ALL、ANY 和 IN。

因此,如果您使用 SQL 数据存储,则只能在谓词中表示一种一对多关系。如果您更改为其他持久性存储,则似乎意味着此特定限制已解除。

From the Predicate Programming Guide:

The Core Data SQL store supports only
one to-many operation per query;
therefore in any predicate sent to the
SQL store, there may be only one
operator (and one instance of that
operator) from ALL, ANY, and IN.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文