Ho due entità denominate "Category" e "Article" che hanno una relazione molti a molti. Voglio formare un predicato che cerca tutti gli articoli in cui category.name è uguale a qualche valore. Ho il seguente:Dati principali: NSPredicate per la relazione molti-a-molti. ("to-many key not allowed here")
NSEntityDescription *entityArticle = [NSEntityDescription entityForName:@"Article" inManagedObjectContext:managedObjectContext];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"categories.name == [cd] %@", category.name];
[request setSortDescriptors:sortDescriptors];
[request setEntity:entityArticle];
[request setPredicate:predicate];
NSMutableArray *results = [[managedObjectContext executeFetchRequest:request error:nil] mutableCopy];
if ([results count] > 0)
NSLog(@"Results found.");
else
NSLog(@"NO results found.");
[request release];
[sortDescriptor release];
[sortDescriptors release];
L'errore che ricevo è *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
ci sono delle opzioni per recuperare i dati desiderati?
una subquery può anche essere quello che ti serve. Vedere: http://stackoverflow.com/questions/11346546/core-data-unsupported-predicate-with-all-and-in – Collin