Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 27 additions & 3 deletions Source/MMRecord/MMRecordMarshaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,34 @@
+ (void)establishPrimaryKeyRelationshipFromProtoRecord:(MMRecordProtoRecord *)protoRecord
toParentRelationshipPrimaryKeyProtoRecord:(MMRecordProtoRecord *)parentRelationshipPrimaryKeyProto;

/**
This method is used when a response contains multiple instances of the same record. MMRecord will
always do its best to create and populate these records and associate them with the appropriate
relationships on various other records. Generally speaking, its expected that a response will
contain either duplicate references to record primary keys, which allow MMRecord to fetch the
appropriate record to associate as a relationship. Or, the response may contain duplicate fully
saturated objects. In this case, the first object will "win", and all other references to that
object will be populated using the first one that is found.

This method is intended as a means to merge those various different response objects together to
create a master instance of a particular record. In some responses an object may contain a subset
of data in one place, and a larger subset of data in another place. In those instances, a user
may want for the larger subset to win, even if it wasn't found by MMRecord first.

You may override this method in a subclass of MMRecordMarshaler to provide this functionality.
@param dictionary The dictionary for the n+1th record response object of a given type and
primary key.
@param protoRecord The proto record created to represent this specific object by MMRecord.
@discussion This method has no default implementation. You must subclass MMRecordMarshaler to
provide your own implementation.
*/
+ (void)mergeDuplicateRecordResponseObjectDictionary:(NSDictionary *)dictionary
withExistingProtoRecord:(MMRecordProtoRecord *)protoRecord;

///-------------------------------
/// @name Public Interface Methods
///-------------------------------

///---------------------------------
/// @name Public Subclassing Methods
///---------------------------------

/**
This method is designed to be subclassed. It should be called to handle the population of a
Expand Down
6 changes: 6 additions & 0 deletions Source/MMRecord/MMRecordMarshaler.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ + (void)establishPrimaryKeyRelationshipFromProtoRecord:(MMRecordProtoRecord *)pr
}
}

+ (void)mergeDuplicateRecordResponseObjectDictionary:(NSDictionary *)dictionary
withExistingProtoRecord:(MMRecordProtoRecord *)protoRecord {
// There is no default implementation for this method. Feel free to provide your own :)
}


#pragma mark - To Many Relationship Test

// TODO: Simplify this method by refactor/extract
Expand Down
3 changes: 3 additions & 0 deletions Source/MMRecord/MMRecordResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ - (MMRecordProtoRecord *)protoRecordWithRecordResponseObject:(id)recordResponseO
}
}
}
} else {
[representation.marshalerClass mergeDuplicateRecordResponseObjectDictionary:recordResponseObject
withExistingProtoRecord:proto];
}

[self uniquelyAddNewProtoRecord:proto toExistingResponseGroups:responseGroups];
Expand Down