Вопрос

I have the following entity mapping and descriptor:

RKEntityMapping *responseUserMapping = [APICallUser RKGetUserMappingForManagedObjectStore:self.appDelegate.managedObjectStore];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseUserMapping
[session.objectManager addResponseDescriptor:responseDescriptor];
                                                                                            method:RKRequestMethodPOST
                                                                                       pathPattern:APICallUserCreatePattern
                                                                                           keyPath:@"user"
                                                                                       statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

Here is the description of the method RKGetUserMappingForManagedObjectStore

+ (RKEntityMapping *) RKGetUserMappingForManagedObjectStore:(RKManagedObjectStore *) store{
    RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:store];
    userMapping.identificationAttributes = @[ @"userId" ];
    [userMapping addAttributeMappingsFromDictionary:@{
     @"id" : @"userId",
     @"email" : @"email",
     @"firstname" : @"firstName",
     @"lastname" : @"lastName",
     @"gender" : @"gender",
     @"time_zone" : @"timeZone",
     @"created_at" : @"createdAt",
     @"nickname" : @"pseudo",
     @"facebook_id" : @"facebookId",
     @"facebook_link_asked_at" : @"lastQueryForFacebookLinkDate",
     @"birthday" : @"birthDate",
     @"city" : @"city",
     @"country" : @"country",
     @"sign_in_count" : @"signInCount",
     @"facebook_token" : @"facebookToken",
     @"facebook_token_expires_at" : @"facebookExpiration",
     @"avatar.id" : @"avatarPhotoId"
     }];
    
    RKEntityMapping *photoMapping = [APICallPhoto RKGetPhotoMappingForManagedObjectStore:store];
    photoMapping.setNilForMissingRelationships = YES;
    [userMapping addConnectionForRelationship:@"avatarPhoto" connectedBy:@{@"avatarPhotoId" : @"photoId"}];
    //[photoMapping addConnectionForRelationship:@"avatarUsers" connectedBy:@{ @"photoId": @"avatarPhotoId" }];
    [userMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"avatar" toKeyPath:@"avatarPhoto" withMapping:photoMapping]];
    
    return userMapping;
}

And the code for the method RKGetPhotoMappingForManagedObjectStore

+ (RKEntityMapping *) RKGetPhotoMappingForManagedObjectStore:(RKManagedObjectStore *) store{
    RKEntityMapping *photoMapping = [RKEntityMapping mappingForEntityForName:@"Photo" inManagedObjectStore:store];
    photoMapping.identificationAttributes = @[ @"photoId" ];
    [photoMapping addAttributeMappingsFromDictionary:@{
     @"id" : @"photoId",
     @"moment_id" : @"momentId",
     @"user_id" : @"userId",
     @"title" : @"title",
     @"description" : @"photoDescription",
     @"file.thumb_url" : @"thumbnailDistURL",
     @"file.mini_url" : @"miniDistURL",
     @"file.little_url" : @"littleDistURL",
     @"file.medium_url" : @"mediumDistURL",
     @"file.public_url" : @"originalDistURL"
     }];
    
    /*RKEntityMapping *momentMapping = [APICallMoment RKGetMomentMappingForManagedObjectStore:store];
    [momentMapping addConnectionForRelationship:@"photos" connectedBy:@{ @"momentId": @"momentId" }];
    [photoMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"moment" toKeyPath:@"moment" withMapping:momentMapping]];
    
    
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:photoMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"photos" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
    
    [[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
    */
    return photoMapping;
}

This is my json that my app received:

{
    "user": {
        "id": 38,
        "email": "test@test.com",
        "firstname": "bob",
        "lastname": "tonny",
        "gender": 0,
        "created_at": "2014-04-19T11:00:55Z",
        "updated_at": "2014-04-19T11:00:55Z",
        "nickname": "bobby",
        "facebook_id": null,
        "birthday": "1990-02-14",
        "city": "",
        "country": "",
        "facebook_token": null,
        "facebook_token_expires_at": null,
        "time_zone": "Europe/Paris",
        "facebook_link_asked_at": null,
        "sign_in_count": 0,
        "confirmed": false,
        "badge": {
            "permanent": 0,
            "contextual": 0
        },
        "avatar": null
    }
}

You can see that there is no relation with device or devices here. But I have the exact following error:

error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0xd0c1770 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: device, devices
The representation inputted to the mapper was found to contain nested object representations at the following key paths: user
This likely indicates that you have misconfigured the key paths for your mappings., NSLocalizedDescription=No mappable object representations were found at the key paths searched., keyPath=null}

I'm currently not able to find where the problem comes from.

The only relation between User and Device is set on the .xcdatamodelId like you can see on the following pictures:

relationship for User

relationship for User

relationship for Device

relationship for Device

I took a lot at the descriptors: session.objectManager.responseDescriptors. There are several descriptors but none about any devices.

If anyone can just see where I'm missing something, I would really like to know it.

Thank you in advance.

Это было полезно?

Решение

I found the solution. It was not obvious at all. After adding my descriptor to the objectManager, I did that:

session.objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

That solved completely my problem. I don't know why it's important to precise here because I already set this property a long time ago on my code..

Edit: It WAS working ! I didn't touch anything but now it's not working. Edit 2: I finally got it :

I was using `[session.objectManager addResponseDescriptor:responseDescriptor]; session.objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

[[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request managedObjectContext:session.objectManager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)`

I changed [RKObjectManager sharedManager] by my variable session.objectManager and everything work fine !

I hope it will help someone else.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top