Skip to content

Commit

Permalink
Fix crash w/ polymorphic errors in JSONSerializer
Browse files Browse the repository at this point in the history
Use a specialized version of normalizeRelationships for errors rather
than relying on the regular one that expects a `type` property.
  • Loading branch information
Jimmy Bourassa committed May 29, 2015
1 parent 65f4881 commit 1b0b7b7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/ember-data/lib/serializers/json-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,27 @@ export default Serializer.extend({
normalizeErrors: function(typeClass, hash) {
this.normalizeId(hash);
this.normalizeAttributes(typeClass, hash);
this.normalizeRelationships(typeClass, hash);
this.normalizeUsingDeclaredMapping(typeClass, hash);
this.normalizeRelationshipErrors(typeClass, hash);
},

/**
Normalize relationship errors for a given error payload
@method normalizeRelationshipErrors
@private
*/
normalizeRelationshipErrors: function(typeClass, hash) {
if (!this.keyForRelationship) {
return;
}

typeClass.eachRelationship(function(key, relationship) {
var payloadKey = this.keyForRelationship(key, relationship.kind, 'deserialize');
if (key !== payloadKey && hash.hasOwnProperty(payloadKey)) {
hash[key] = hash[payloadKey];
delete hash[payloadKey];
}
}, this);
},

/**
Expand Down

0 comments on commit 1b0b7b7

Please sign in to comment.