Apostolos
Apostolos

Reputation: 409

RKConnectionDescription unstable with Restkit 0.20.3

I have two entities from two different web services which have a many to many relationship.

entity A { NSString *id, NSString *details }

entity B { NSString *key, NSString *value, NSString *type, NSString *foreignId }

and I try to map the entity B :

+ (RKObjectMapping *)mapping { RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([self class]) inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
    [mapping addAttributeMappingsFromDictionary:@{
                                                  @"key": @"key",
                                                  @"id":@"foreignId",
                                                  @"type":@"type",
                                                  @"value":@"value"
                                                  }];

    mapping.identificationAttributes = @[@"featureKey",@"type",@"foreignID"];
    [mapping addConnectionForRelationship:@"homeApplianceDatas" connectedBy:@{@"foreignId":@"id"}];

    return mapping;
}

In my test json all entities of type B have the same foreignID "Car" but only a few of them get a relation to an "A" entity (about 15%) !!!

Any Idea?

Upvotes: 0

Views: 49

Answers (1)

Wain
Wain

Reputation: 119031

When using foreign key mapping, if no destination object is found then mo connection will (can) be made. The connection won't be processed again later.

Also (and this could well be considered a bug in RestKit), any new foreign key mapping relationship contents replace any previous relationship contents. There is no API available to modify this behaviour (as there is for nested relationship processing assignment policy).

So, in a number of cases you will need to process the foreign key information yourself in order to ensure that everything which needs to be connected is actually connected. You could raise an issue against RestKit w.r.t the assignment policy, but the first issue is a design issue for you.

Upvotes: 0

Related Questions