在这里,尝试从我的两个实体名称中获取记录:Resgistration&独特。和他们之间的关系名称是roshan。 当m执行它时显示错误:'NSInvalidArgumentException',原因:'在这里不允许多对键'
NSManagedObjectContext *context = [appDelegate manageObjectContext];
NSError *error = nil;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"roshan.number == %@", @"1"];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Resgistration" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
[request setPredicate:predicate];
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Unique",nil]];
[request setIncludesSubentities:YES];
NSArray* returnArray = [context executeFetchRequest:request error:&error];
if([returnArray count] > 0) {
Resgistration* reg = [returnArray objectAtIndex:0];
NSLog(@"%@ %@", reg.name, reg.number);
}
答案 0 :(得分:2)
roshan
是一个多对多的关系,所以“roshan.number == 1”这个陈述含糊不清。