Restkit:使用子字段“fields.attr”进行特定映射进入字段“attr”

发布于 2024-12-10 11:30:49 字数 2253 浏览 0 评论 0原文

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

我有这个数据模型:

@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];

Hi, i need some advices to know if the stuff i try to do is possible.

I have this data model :

@interface Accommodation : NSManagedObject {
@private
}

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

And i receive the following Json flood (generated by 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": ""
                }
            }
        ], 

    }
  }
]

When i try to map fields.photo_set into photo_set:

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

I obtain the famous:

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

My question is "It is possible to do what i try to do ??"

Thank you for your help !

PS : These are my mapping rules :

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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文