我要拉我的头发试图找出为什么这是行不通的。搜索CoreData关系
我有两个实体:
Quote
Customer
一个Quote
有一个Customer
一个一对一关系属性简称“customer
”。客户有一个CoreData objectID
(显然)。我试图搜索所有报价,然后根据Customer
objectID
返回具有与其关联的特定客户的报价。通过我设法让这所有的教程阅读,但我不断收到崩溃:
+ (void)fetchQuotesForCustomerID:(NSManagedObjectID*)objectID results:(void(^)(NSError* error, NSArray *fetchedResults))completion {
NSManagedObjectContext *context = [[QuoteGenerator sharedGenerator] managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Quote"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"customer.objectID == %@", objectID];
[fetchRequest setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
NSLog(@"fetch error = %@", [error localizedDescription]);
completion(error, nil);
} else {
NSLog(@"fetch count = %d", fetchedObjects.count);
completion(nil, fetchedObjects);
}
}
输出错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath customer.objectID not found in entity <NSSQLEntity Quote id=13>'
是在断言设置错了吗?通过文档阅读说,你可以使用点语法来访问谓词中的属性。
请帮助...
如果一个客户能你为什么不使用一个一对多的关系,简单地使用核心数据找到相关引用的对象有很多报价? – Gary 2013-02-26 05:41:20
@加里谢谢你的帮助。带我到正确的答案! – random 2013-02-26 05:48:33