我在添加关系后获取对象时遇到问题.我第一次获取类别,总是找到,然后当我添加到关系时,找不到以下类别.
这种关系是一种Many-To-Many.
例:
categoryId = 10如果几个类别相同id,则categoryId = 10找不到
NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[private setParentContext:self.model.context];
__block NSError *error = nil;
[private performBlockAndWait:^{
GPDeal *deal = [EKManagedObjectMapper objectFromExternalRepresentation:dic withMapping:[GPDeal objectMapping] inManagedObjectContext:private];
for (NSDictionary *dic in responseObject[@"response"]) {
GPCategory *category;
//The first time always found
if ((category = [GPCategory MR_findFirstByAttribute:@"catId" withValue:dic[@"mainAttribute"] inContext:private])) {
NSLog(@"Found");
[category addDealsObject:deal];
} else {
NSLog(@"Not Found");
}
}
}];
NSError *PrivateError = nil;
if (![private …Run Code Online (Sandbox Code Playgroud)