Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[10.3] RKObjectMapping inverseMapping does not preserve date formatters #1058

Closed
levigroker opened this Issue Dec 6, 2012 · 1 comment

Comments

Projects
None yet
2 participants

When creating an inverse mapping from a RKObjectMapping object the 'dateFormaters' and 'preferredDateFormatter' from the object are not preserved in the resulting inverse mapping object.

See the inverseMapping routines, where no attempt to preserve this state is made:

- (RKObjectMapping *)inverseMappingAtDepth:(NSInteger)depth
{
  NSAssert(depth < MAX_INVERSE_MAPPING_RECURSION_DEPTH, @"Exceeded max recursion level in inverseMapping. This is likely due to a loop in the serialization graph. To break this loop, specify one-way relationships by setting serialize to NO in mapKeyPath:toRelationship:withObjectMapping:serialize:");
  RKObjectMapping *inverseMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
  for (RKObjectAttributeMapping *attributeMapping in self.attributeMappings) {
    [inverseMapping mapKeyPath:attributeMapping.destinationKeyPath toAttribute:attributeMapping.sourceKeyPath];
  }

  for (RKObjectRelationshipMapping *relationshipMapping in self.relationshipMappings) {
    if (relationshipMapping.reversible) {
      RKObjectMappingDefinition *mapping = relationshipMapping.mapping;
      if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
        RKLogWarning(@"Unable to generate inverse mapping for relationship '%@': %@ relationships cannot be inversed.", relationshipMapping.sourceKeyPath, NSStringFromClass([mapping class]));
        continue;
      }
      [inverseMapping mapKeyPath:relationshipMapping.destinationKeyPath toRelationship:relationshipMapping.sourceKeyPath withMapping:[(RKObjectMapping *)mapping inverseMappingAtDepth:depth+1]];
    }
  }

  return inverseMapping;
}

- (RKObjectMapping *)inverseMapping
{
  return [self inverseMappingAtDepth:0];
}
Owner

blakewatters commented Dec 22, 2012

Fix incoming.

@blakewatters blakewatters added a commit that referenced this issue Dec 22, 2012

@blakewatters blakewatters Reimplement inverseMapping so that it no longer sucks. fixes #864, #1058


* Inversing non intelligently walks the mapping graph, ensuring that cyclic graphs are resolved properly
* Copy all attributes from the parent to the inverse mapping (date formatters, etc)
7984d4f

@stojanovicigi stojanovicigi added a commit to CenterDevice/RestKit that referenced this issue Dec 12, 2013

@blakewatters @stojanovicigi blakewatters + stojanovicigi Reimplement inverseMapping so that it no longer sucks. fixes #864, #1058


* Inversing non intelligently walks the mapping graph, ensuring that cyclic graphs are resolved properly
* Copy all attributes from the parent to the inverse mapping (date formatters, etc)
17db848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment