RestKit Object Mapping Relationships without KVC

后端 未结 1 1853
南旧
南旧 2020-12-05 16:54

After reading the Object Mapping-Guide on GitHub for RestKit my problem didn\'t disappear, so perhaps somebody can say if RestKit could deal with the following idea.

1条回答
  •  醉酒成梦
    2020-12-05 17:16

    Yes, RestKit can hydrate this relationship for you at mapping time. On your RKManagedObjectMapping for your Contact model, you will need to do the following:

    • Add a relationship mapping to the parent Company: [objectMapping mapRelationship:@"company" withMapping:companyMapping]
    • Map the companyID attribute onto your Contact model
    • Ensure that you have the primaryKeyAttribute configured on both classes
    • Instruct RestKit to hydrate the relationship: [objectMapping connectRelationship:@"company" withObjectForPrimaryKeyAttribute:@"companyID"];

    After RestKit has completed mapping a payload, it will pass back through the collection and hydrate any relationships. The processing is deferred until after mapping in case the payload actually creates objects that you need to satisfy the connections.

    On the development branch, there is an alternative workflow available to you. Earlier this week I added support for hydrating a has-many relationship using an array of ID's in the payload. This would let you send the list of Contacts that belong to a company down in the payload instead. It may be more efficient for your use case.

    Additional details from my post to the RestKit mailing list: http://groups.google.com/group/restkit/msg/416951f86b2862d1

    0 讨论(0)
提交回复
热议问题