1

嗨,我需要一些建议来了解我尝试做的事情是否可行。

我有这个数据模型:

@interface Accommodation : NSManagedObject {
@private
}

@property (nonatomic, retain) NSNumber * AccommodationId;
@property (nonatomic, retain) NSSet *photo_set;

我收到以下 Json 洪水(由 Django 生成):

[
  {
    "pk": 13570, 
    "model": "catalog.accommodation", 
    "fields": {
        "thematics": [
            3, 
            15, 
            48, 
            61
        ], 
        "code": "code_acc_12", 
        "booking_url": null,
        "photo_set": [
            {
                "pk": 58346, 
                "model": "gallery.photo", 
                "fields": {
                    "url": "http:www.google.com", 
                    "type": "main", 
                    "label": ""
                }
            }
        ], 

    }
  }
]

当我尝试将 fields.photo_set 映射到 photo_set 时:

    [accommodationMapping mapRelationship:@"fields.photo_set" withMapping:photoMapping];

我得到了著名的:

    Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Accommodation 0x5c6afa0> valueForUndefinedKey:]: the entity Accommodation is not key value coding-compliant for the key "AccommodationId".'

我的问题是“有可能做我想做的事吗??”

谢谢您的帮助 !

PS:这些是我的映射规则:

RKManagedObjectMapping* photoMapping = [RKManagedObjectMapping mappingForClass:[Photos class] ];
photoMapping.primaryKeyAttribute = @"PhotoId";
[photoMapping mapKeyPath:@"pk" toAttribute:@"PhotoId"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:photoMapping];    

RKManagedObjectMapping* accommodationMapping = [RKManagedObjectMapping mappingForClass:[Accommodation class]];
accommodationMapping.primaryKeyAttribute = @"AccommodationId";
[accommodationMapping mapKeyPath:@"pk" toAttribute:@"AccommodationId"];
[accommodationMapping mapKeyPath:@"fields.code" toAttribute:@"code"];
[accommodationMapping mapRelationship:@"fields.photo_set" withMapping:photoMapping];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:accommodationMapping];
4

0 回答 0