简体   繁体   中英

Issue with fetching core data objects using 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];

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;
}

Any idea why?

If I see it correctly, the predicate should be

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM