У меня есть основная структура данных Books and Bundles. Книга может принадлежать одному или нескольким пакетам, поэтому у меня есть атрибут «многие ко многим» между ними. В книге этот атрибут называется fromBundle.
У меня есть свой класс для каждой сущности. Этот класс был написан, когда вместо отношения «многие ко многим» у меня было просто отношение ко многим... так что в то время fromBundle не был NSSet. Моя проблема в том, что мне нужно создать предикат, который мог бы заглянуть внутрь NSSet fromBundle и посмотреть, содержит ли набор искомый пакет.
Это код, который у меня был до изменения.
Bundle *aBundle = [Bundle bundleComNumber:aNumber inManagedObjectContext:context];
NSArray *all = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Book" inManagedObjectContext:context];
// the problem is on the next line... as I see, the line is not looking inside the NSSet
// I may be wrong, but when I run this, it crashes and stops on the executeFetchRequest line
// saying **to-many key not allowed here**
request.predicate = [NSPredicate predicateWithFormat:
@"(fromBundle == %@)", aBundle];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:[NSArray arrayWithObjects: @"Name", @"Number", nil]];
NSSortDescriptor *sortByItem = [NSSortDescriptor sortDescriptorWithKey:ordem ascending:YES selector:@selector(compare:)];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByItem];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
all = [context executeFetchRequest:request error:&error]; // it is crashing here saying **to-many key not allowed here**
[request release];
return all;
что мне не хватает? Благодарность