So the problem is that when I'm trying to load entity from here I'm not getting things to work. My Pathpatterns seems to be wrong. Here's my Mapping and Descriptor:
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]];
So when I use pathPattern:nil it works, but if no answer is returned by url it just tries to put another responsedescriptor to the response and gives me random data :)
The question is, if I have the car ID in the middle of the pattern, how should I declare it?
Thank you!
Edit1: This is how I do request:
- (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];
}];
}
From your trace log there is some problem with your managed objects, not your mappings. Your entities are obviously defined in the model and with the correct names and with the appropriate attributes. So it looks like either you created classes for the entities but wrongly or that the object manager isn't being provided with an / the correct object store reference.
Your log contains CoreData: error: Failed to call designated initializer on NSManagedObject class 'Stat' and [<Stat 0xa68b7c0> valueForUndefinedKey:]: the entity (null) is not key value coding-compliant for the key "statID". which are both issues to do with the entity creation / referencing. It isn't clear how that happens based on the code posted.
Try changing your path pattern to remove the leading slash:
@"api/cars/:carID/features.json"
when defining your statsDescriptor as that can cause the pattern to not match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With