Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with AFMMRecordResponseSerializer threading #88

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/MMRecord/MMRecordProtoRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
*/
+ (MMRecordProtoRecord *)protoRecordWithDictionary:(NSDictionary *)dictionary
entity:(NSEntityDescription *)entity
representation:(MMRecordRepresentation *)representation;
representation:(MMRecordRepresentation *)representation
primaryKeyValue:(id)primaryKeyValue;


///---------------------------
Expand Down
5 changes: 3 additions & 2 deletions Source/MMRecord/MMRecordProtoRecord.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ @implementation MMRecordProtoRecord

+ (MMRecordProtoRecord *)protoRecordWithDictionary:(NSDictionary *)dictionary
entity:(NSEntityDescription *)entity
representation:(MMRecordRepresentation *)representation {
representation:(MMRecordRepresentation *)representation
primaryKeyValue:(id)primaryKeyValue {
NSParameterAssert([NSClassFromString([entity managedObjectClassName]) isSubclassOfClass:[MMRecord class]]);
MMRecordProtoRecord *protoRecord = [[MMRecordProtoRecord alloc] init];
protoRecord.dictionary = dictionary;
protoRecord.entity = entity;
protoRecord.primaryKeyValue = [representation primaryKeyValueFromDictionary:dictionary];
protoRecord.primaryKeyValue = primaryKeyValue;
protoRecord.relationshipProtosDictionary = [NSMutableDictionary dictionary];
protoRecord.relationshipDescriptionsDictionary = [NSMutableDictionary dictionary];
protoRecord.hasRelationshipPrimarykey = [representation hasRelationshipPrimaryKey];
Expand Down
39 changes: 18 additions & 21 deletions Source/MMRecord/MMRecordResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,32 @@ - (MMRecordProtoRecord *)protoRecordWithRecordResponseObject:(id)recordResponseO
}

id primaryValue = [representation primaryKeyValueFromDictionary:recordResponseObject];
MMRecordProtoRecord *proto = [recordResponseGroup protoRecordForPrimaryKeyValue:primaryValue];

if (proto == nil) {
proto = [MMRecordProtoRecord protoRecordWithDictionary:recordResponseObject
entity:entity
representation:representation];


if (proto.hasRelationshipPrimarykey == NO) {
if (proto.primaryKeyValue == nil) {
if (self.options.entityPrimaryKeyInjectionBlock != nil) {
proto.primaryKeyValue = self.options.entityPrimaryKeyInjectionBlock(proto.entity,
proto.dictionary,
parentProtoRecord);
}
}

if (proto.primaryKeyValue == nil) {
if (primaryValue == nil) {
if (self.options.entityPrimaryKeyInjectionBlock != nil) {
primaryValue = self.options.entityPrimaryKeyInjectionBlock(entity,
recordResponseObject,
parentProtoRecord);
if (primaryValue == nil) {
MMRecordDebugger *debugger = self.options.debugger;
NSString *errorDescription = [NSString stringWithFormat:@"Creating proto record with no primary key value. \"%@\"", proto];
NSString *errorDescription = [NSString stringWithFormat:@"No primary key value for response object. \"%@\"", recordResponseObject];
NSDictionary *parameters = [debugger parametersWithKeys:@[MMRecordDebuggerParameterRecordClassName,
MMRecordDebuggerParameterErrorDescription,
MMRecordDebuggerParameterEntityDescription]
values:@[proto.entity.managedObjectClassName,
values:@[entity.managedObjectClassName,
errorDescription,
proto.entity]];
entity]];
[debugger handleErrorCode:MMRecordErrorCodeMissingRecordPrimaryKey withParameters:parameters];
}
}
}
MMRecordProtoRecord *proto = [recordResponseGroup protoRecordForPrimaryKeyValue:primaryValue];

if (proto == nil) {
proto = [MMRecordProtoRecord protoRecordWithDictionary:recordResponseObject
entity:entity
representation:representation
primaryKeyValue:primaryValue];

} else {
[representation.marshalerClass mergeDuplicateRecordResponseObjectDictionary:recordResponseObject
withExistingProtoRecord:proto];
Expand Down