我有Books和Bundles的核心数据结构。一本书可以属于一个或多个包,因此,我在两者之间具有多对多属性。在这本书中,这个属性是从Bunle中调用的。
我为每个实体提供课程。这个类写的时候是多对多的,我只有一对多的关系...所以,那时,来自邦德并不是一个NSSet。我的问题是这个,我必须构建一个可以查看fromBundle NSSet的谓词,看看该集合是否包含我正在寻找的包。
这是我在更改之前的代码。
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;
我错过了什么?
感谢
答案 0 :(得分:2)
您是否尝试使用类似@"%@ IN fromBundle"
的谓词?