0

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?

Apostolos
  • 409
  • 3
  • 13
  • Is that 15% all received in a single response (and the other 85% is from a previous response)? – Wain Apr 22 '14 at 15:23
  • The Service for the B entity could be triggered multiple times, sometimes even before entity A exists – Apostolos Apr 22 '14 at 15:35

1 Answers1

0

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • I used a workaround to add the missing connection, but I wanted to know why rest kit is causing so much trouble. The problem with rest kit is that it does not have a standard behaviour. Sometimes it connects ALL entities, sometimes a few, sometimes none. – Apostolos Apr 23 '14 at 05:59
  • I'd need to know more about the tests. If you run the same test twice you should get exactly the same results... – Wain Apr 23 '14 at 07:39