As a newbie RestKit user I'm having a conceptual understanding problem with CoreData relationship mapping.
Let's say we have a CoreData model with just two entities in master/detail relationship:
@interface Master : NSManagedObject
@property (nonatomic, retain) NSString *objectId;
@property (nonatomic, retain) NSString *display;
@property (nonatomic, retain) NSSet *childrens;
@end
@interface Children : NSManagedObject
@property (nonatomic, retain) NSString *objectId;
@property (nonatomic, retain) NSString *display;
@property (nonatomic, retain) Master *father;
@end
The RestKit mapping for this model is:
RKEntityMapping *masterMapping = ...
RKEntityMapping *childrenMapping = ...
... property mappings ...
masterMapping.identificationAttributes = @[ @"objectId" ];
childrenMapping.identificationAttributes = @[ @"objectId" ];
[masterMapping addPropertyMapping:[RKRelationshipMapping
relationshipMappingFromKeyPath:@"childrens" toKeyPath:@"childrens"
withMapping:childrensMapping]];
[childrenMapping addPropertyMapping:[RKRelationshipMapping
relationshipMappingFromKeyPath:@"father" toKeyPath:@"father"
withMapping:masterMapping]];
Here is how the http get response is modeled (I can change it):
{
objectId: "3",
display: "a master object",
childrens: [
{
objectId: "1",
display: "a child object",
father: { objectId: "3" }
},
{
objectId: "2",
display: "another child object",
father: { objectId: "3" }
}
]
}
The problem is that the previous mapping definition would lead to a circular mapping error from RestKit when associating it with some RKResponseDescriptor.
I've read RestKit documentation and many stackoverflow.com similar threads, but still I don't understand how to set up a full CoreData model relationship mapping, provided that I need to have both relations available in my code (i.e. I need to explicitly access father from a children, and childrens from a master entity).
Any help will be appreciated.
Many thanks in advance!