问题在于:
我请求一个对象,它将从远程服务器获取并持久保存到dataBase没有问题。我是这样做的:
我已经定义了一条路线:
+ (RKRoute *)getRestMenuRoute
{
return [RKRoute routeWithRelationshipName:@"rest_menu" objectClass:[Restaurant class] pathPattern:@"menu/:restaurantID" method:RKRequestMethodGET];
}
- (void)LoadRestaurantMenu:(Restaurant *)resturant withCompletionBlock:(completion)completionBlock
{
[self getObjectsAtPathForRelationship:@"rest_menu" ofObject:resturant parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
completionBlock(YES, nil);
}
failure: ^(RKObjectRequestOperation *operation, NSError *error)
{
//creating a new error which contains HTTP status code
}];
}
self
是RKObjectManager
MenuMappingProvider:
RKEntityMapping *menuMapping = [RKEntityMapping mappingForEntityForName:@"Menu" inManagedObjectStore:managedObjectStore];
menuMapping.identificationAttributes = @[@"menuID"];
[menuMapping addAttributeMappingsFromDictionary:@{
@"Setting.MinOrder":@"minOrder" and more .....
}];
NSDictionary *restaurantIDMapping = @{@"@metadata.routing.parameters.restaurantID": @"restaurantID"};
[menuMapping addAttributeMappingsFromDictionary:restaurantIDMapping];
[menuMapping addConnectionForRelationship:@"restaurant" connectedBy:@{@"restaurantID":@"restaurantID"}];
但是当我发送批量请求时,restKit会记录对象检索和映射成功,但是当我查询餐馆菜单时,它会记录nil
!没有对象已保存到dataBase。
这是我的批量请求:
- (void)syncRestaurantsMenuWithProgressCallBack:(progressCallback)progressCallBack
{
[self enqueueBatchOfObjectRequestOperationsWithRoute:[HARouter getRestMenuRoute] objects:[Restaurant findAll] progress:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
CGFloat progress = (CGFloat)numberOfFinishedOperations/(CGFloat)totalNumberOfOperations;
progressCallBack(progress);
NSLog(@"sync menu progress:%f", progress);
} completion:^(NSArray *operations) {
NSLog(@"all menus synced!");
}];
}
每个获取对象的RestKit日志:
restkit.network:RKObjectRequestOperation.m:222 GET 'https://restaurant.com/menu/2176' (200 OK / 1 objects) [request=4.3484s mapping=0.0048s total=4.3588s]
你的想法是什么?你怎么看?我的问题是什么?
更新
当我批量排队时,从restaurant
实体到Menu
实体的Restaurant
关系将无法建立!我在名为Menu
的{{1}}实体中定义了一个外键,并使用此外键建立从restaurantID
到Menu
的连接。 RestKit将从路径元数据中设置此外键,然后检查餐馆列表以找到具有相同Id的餐馆,然后建立从菜单到餐馆的连接,反之亦然。
RestKit CoreData跟踪日志:
Restaurant
更新2
首先我获得餐馆列表,他们的基本信息,然后在完成块中我获取菜单。关系是一个2一。
因此,关系是一个2 1这是否可以在映射中为2015-12-07 14:11:47.290 MyApp[28491:16381752] T restkit.core_data:RKRelationshipConnectionOperation.m:193 Connecting relationship 'restaurant' with mapping: <RKForeignKeyConnectionDescription:0x7fe3715b4c20 connecting Relationship 'restaurant' from Entity 'Menu' to Destination Entity 'Restaurant' with attributes={
restaurantID = restaurantID;
}>
2015-12-07 14:11:47.290 MyApp[28491:16381752] D restkit.core_data:RKRelationshipConnectionOperation.m:204 Connected relationship 'restaurant' to object '(null)'
实体提供identificationAttribute
?
链接已更新