mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-13 22:45:23 +08:00
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:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user