Here is the model I have: http://www.girardet.ch/model.png
My goal is to retrieve all the Quotes with these criterias:
- belong to a specific theme : the name_en attribute of Themes
- order by relevancy
- filtered by Authors (with the alias attribute of Authors)
Here is my code:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ThemeEntries" inManagedObjectContext:_context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"relevancy" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// predictate - filter
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"theme.name_en=%@ AND quotes.author.alias=%@",@"mytheme", @"myauthor"];
[fetchRequest setPredicate:predicate];
I get the "to-many key not allowed here" error.
If I instead use this predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"theme.name_en=%@, @"mytheme"];
it works well and I can loop over the ThemeEntries
that I get and get all my quotes... But it's not filtered by authors.
What can I do to filter by Authors?