使用RestKit映射子对象时,将父对象添加为属性

时间:2012-07-06 07:32:00

标签: objective-c ios cocoa-touch restkit

我对以下XML有一个非常简单的RestKit映射:

<category name="religious">
  <book isbn="42">HHGTTG</book>
  <book isbn="7">The bible</book>
</category>

现在解析这个时,我得到一个category对象,其中包含两个book个对象。现在在我的book对象中,我希望引用category

这似乎是一件非常容易实现的事情,但我在Object Mapping Documentation中找不到任何内容。

更新:这就是我的映射:

RKObjectMapping *bookMapping = [RKObjectMapping mappingForClass:[Book class]];
[bookMapping mapKeyPath:@"isbn" toAttribute:@"isbn"];

RKObjectMapping* categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping mapKeyPath:@"name" toAttribute:@"name"];
// Relationship to book
[categoryMapping mapKeyPath:@"book" toRelationship:@"books" withMapping:bookMapping];

0 个答案:

没有答案