Search code examples
objective-crestkit

RKRelationshipConnectionOperation managedObject invalid in start method


I'm having an issue using RestKit and trying to connect two entities using foreign keys.

Let's say I have two entities A and B and a relationship A <->> B I create the connection in the following way

RKEntityMapping *aEntity = ...;
[aEntity addAttributeMappingsFromDictionary: ...]

RKEntityMapping *bEntity = ...;
[bEntity addAttributeMappingsFromDictionary: ...]

RKConnectionDescription *aConnection = [[RKConnectionDescription alloc] 
                                        initWithRelationship:[[b.entity
                                        relationshipsByName][@"a"]
                                                  attributes:@{@"aID" : @"id"}];
[bEntity addConnection:aConnection];

When data is received from the server I get an EXC_BAD_INSTRUCTION exception. The exception fires in the following method: static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescription *connection, NSManagedObject *managedObject) at the line id sourceValue = [managedObject valueForKey:sourceAttribute];

This method is called in the RKRelationshipConnectionOperation runloop. What I noticed is that the managedObject is valid when the operation is created (in the init), but becomes invalid in the start method (the debugger gives the address, but no information on the object is printed)

I couldn't find any related issue, so I'm sure I'm missing something

EDIT: Regarding the comments, maybe this is the reason why this does not work. I fetch before all the A entities. In a separate fetch, I fetch some B entities. The JSON is something like

{
   "id" : 1,
   "someattr" : "somevalue",
   "aID" : 5
}

Solution

  • Updating to Restkit 0.25 solved the issue.