使用NSPredicate提取核心数据对象的问题 [英] Issue with fetching core data objects using NSPredicate

查看:119
本文介绍了使用NSPredicate提取核心数据对象的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始之前,让我告诉你我的数据模型是什么样子:

Before I start let me give you how my data model looks like:

然后我有一个带有以下谓词的抓取请求:

I then have a fetch request with the following predicate:

NSArray *allowedPackNames = @[@"success, happiness, free"];
            self.fetchedResultsController = [Author MR_fetchAllGroupedBy:nil
                                                           withPredicate:[NSPredicate predicateWithFormat:@"ANY quotes.quote.pack.packName IN %@", allowedPackNames]
                                                                sortedBy:AuthorKeys.name
                                                               ascending:YES
                                                                delegate:self];

我想获取所有拥有成功或幸福或免费的packName的报价的作者。
作者有一个NSSet的引号,你可以在下面的关系表中看到。但是当我执行这个我得到以下错误:

I wanted to fetch all Authors that has a Quote with packName of success or happiness or free. Author has a NSSet of quotes as you can see in the relationship table below. However when I execute this I get the following error:

CoreData: error: (1) I/O error for database at /Users/Abdul/Library/Application Support/iPhone Simulator/6.1/Applications/DA17421B-A54D-42E3-9694-FDCBFF7F8BA4/Library/Application Support/MyCoolApp/MyCoolApp.sqlite.  SQLite error code:1, 'no such column: t2.ZQUOTE'
2013-04-05 15:26:47.175 MyCoolApp[78622:c07] Core Data: annotation: -executeRequest: encountered exception = I/O error for database at /Users/Aditya/Library/Application Support/iPhone Simulator/6.1/Applications/DA17421B-A54D-42E3-9694-FDCBFF7F8BA4/Library/Application Support/MyCoolApp/MyCoolApp.sqlite.  SQLite error code:1, 'no such column: t2.ZQUOTE' with userInfo = {
    NSFilePath = "/Users/Abdul/Library/Application Support/iPhone Simulator/6.1/Applications/DA17421B-A54D-42E3-9694-FDCBFF7F8BA4/Library/Application Support/MyCoolApp/MyCoolApp.sqlite";
    NSSQLiteErrorDomain = 1;
}

推荐答案

如果我看到它的正确,谓词应该是

If I see it correctly, the predicate should be

[NSPredicate predicateWithFormat:@"ANY quotes.pack.packName IN %@", allowedPackNames]

ie您必须删除报价,这是报价实体的属性,而不是关系。

i.e. you have to remove "quote", which is an attribute of the Quote entity, not a relationship.

这篇关于使用NSPredicate提取核心数据对象的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆