Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
levigroker opened this Issue · 1 comment

2 participants

@levigroker

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];
}
@blakewatters

Fix incoming.

@blakewatters blakewatters referenced this issue from a commit
@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 referenced this issue from a commit in CenterDevice/RestKit
@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)
17db848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.