Michal Jurník
Michal Jurník

Reputation: 830

Restkit - the entity (null) is not key value coding-compliant for the key "rows"

I'm using RESTKIT 0.20 and I have problem with mapping. Could anyone tell me where is error? Thx and there's my code:

RKObjectMapping* pageMapping = [RKEntityMapping mappingForEntityForName:@"Page" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[pageMapping addAttributeMappingsFromArray:@[ @"rows", @"columns" ]];


RKObjectMapping* magazineMapping = [RKEntityMapping mappingForEntityForName:@"Magazine" inManagedObjectStore:[RKManagedObjectStore defaultStore]];

[magazineMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"pages"
                                                                               toKeyPath:@"pages"
                                                                             withMapping:pageMapping]];


RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:magazineMapping pathPattern:nil keyPath:@"magazine" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", kBasePath, [magazine contentPath]]];
NSURLRequest *r = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:r responseDescriptors:@[ responseDescriptor ]];

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    RKLogInfo(@"Load collection of Articles: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    RKLogError(@"Operation failed with error: %@", error);
}];

[objectRequestOperation start];

There's entity Magazine:

@interface Magazine : NSManagedObject

@property (strong) NSString * contentPath;
@property (strong) NSDate * date;
@property (strong) NSString * icon;
@property (strong) NSString * magazineID;
@property (strong) NSDecimalNumber * price;
@property (strong) id priceLocale;
@property (strong) NSString * title;
@property (strong) Page *pages;

And finally there's Page entity:

@class Magazine;

@interface Page : NSManagedObject

@property (strong) NSString * content;
@property (strong) NSNumber * contentID;
@property (strong) NSNumber * columns;
@property (strong) NSNumber * rows;
@property (strong) NSString *pageID;
@property (strong) Magazine *assignedMagazine;

The error must be in mapping Page entity, because others "downloading" methods are without problem.

Upvotes: 1

Views: 1233

Answers (1)

Khawar
Khawar

Reputation: 9241

Use mapping like this:

RKManagedObjectMapping *mappingPage = [RKManagedObjectMapping mappingForClass:[Page class] inManagedObjectStore:self.objectStore];
    mappingPage.setDefaultValueForMissingAttributes = NO;
    mappingPage.primaryKeyAttribute = @"contentID";
    [mappingPage mapKeyPathsToAttributes:

     @"CONTENT_FROM_WEBSERVICE", @"content",
     @"ID_FROM_WEBSERVICE", @"contentID",
     @"COLUMNS_FROM_WEBSERVICE", @"columns",
     @"ROWS_FROM_WEBSERVICE", @"rows",     
     nil];

Upvotes: 1

Related Questions