Be sure to set the mapping format on the mapper when it is set on the manager. Don't create duplicate objects when mapping from JSON

This commit is contained in:
Blake Watters
2010-02-25 12:05:45 -05:00
parent 044f17c2e1
commit 1908bfb1d6
3 changed files with 8 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ static RKModelManager* sharedManager = nil;
- (void)setFormat:(RKMappingFormat)format {
_format = format;
_mapper.format = format;
if (RKMappingFormatXML == _format) {
[_client setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
} else if (RKMappingFormatJSON == _format) {

View File

@@ -151,7 +151,13 @@
id object = nil;
if ([class respondsToSelector:@selector(findByPrimaryKey:)]) {
// TODO: factor to class method? incase it is not a number
NSNumber* pk = [dict objectForKey:[class primaryKey]];
NSString* primaryKey = nil;
if ([class respondsToSelector:@selector(formatElementName:forMappingFormat:)]) {
primaryKey = [class formatElementName:[class primaryKeyElement] forMappingFormat:RKMappingFormatJSON];
} else {
primaryKey = [class primaryKeyElement];
}
NSNumber* pk = [dict objectForKey:primaryKey];
object = [class findByPrimaryKey:pk];
}
// instantiate if object is nil