From 1b0b7b79feb83432eed4f2e17d76b2cb1e390709 Mon Sep 17 00:00:00 2001 From: Jimmy Bourassa Date: Mon, 11 May 2015 11:08:13 -0400 Subject: [PATCH] Fix crash w/ polymorphic errors in JSONSerializer Use a specialized version of normalizeRelationships for errors rather than relying on the regular one that expects a `type` property. --- .../lib/serializers/json-serializer.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/ember-data/lib/serializers/json-serializer.js b/packages/ember-data/lib/serializers/json-serializer.js index 7a03adaa7d4..c3c48a8bcf7 100644 --- a/packages/ember-data/lib/serializers/json-serializer.js +++ b/packages/ember-data/lib/serializers/json-serializer.js @@ -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); }, /**