所以问题是当我试图从这里加载实体时,我没有让事情正常工作。我的路径模式似乎是错误的。这是我的映射和描述符:
RKEntityMapping *statsMapping = [RKEntityMapping mappingForEntityForName:@"Stat" inManagedObjectStore:managedObjectStore];
[statsMapping addAttributeMappingsFromDictionary:@{
@"sort_id" : @"sortID",
@"id" : @"statID",
@"deleted" : @"deletedFlag",
@"created_at": @"createdAt",
@"updated_at": @"updatedAt"
}];
statsMapping.identificationAttributes = @[ @"statID" ];
[statsMapping addAttributeMappingsFromArray:@[ @"title"]];
RKEntityMapping *featuresMapping = [RKEntityMapping mappingForEntityForName:@"Feature" inManagedObjectStore:managedObjectStore];
[featuresMapping addAttributeMappingsFromDictionary:@{
@"sort_id" : @"sortID",
@"id" : @"featureID",
@"deleted" : @"deletedFlag",
@"created_at": @"createdAt",
@"updated_at": @"updatedAt",
}];
featuresMapping.identificationAttributes = @[ @"featureID" ];
[featuresMapping addAttributeMappingsFromArray:@[ @"title", @"value"]];
[statsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"features" toKeyPath:@"features" withMapping:featuresMapping]];
RKResponseDescriptor *statsDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:statsMapping
pathPattern: @"/api/cars/:carID/features.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptorsFromArray:@[newsDescriptor, catalogDescriptor, statsDescriptor]];
因此,当我使用 pathPattern:nil 时它可以工作,但是如果 url 没有返回任何答案,它只会尝试将另一个 responsedescriptor 放入响应并给我随机数据:)
问题是,如果我在图案中间有车牌,我应该怎么申报呢?
谢谢!
Edit1:这就是我要求的方式:
- (void)getStats:(NSNumber *)carID
{
[[RKObjectManager sharedManager] getObjectsAtPath:[NSString stringWithFormat:@"api/cars/%@/features.json", carID]
parameters:@{@"auth_token" : [Constants authToken]}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Load complete: Stats loaded");
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Load failed with error: %@", error);
[self showError:error withDelay:3];
}];
}