Restkit:使用子字段“fields.attr”进行特定映射进入字段“attr”
嗨,我需要一些建议来知道我尝试做的事情是否可行。
我有这个数据模型:
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论