Skip to content

Commit

Permalink
Allow EmbeddedRecords error to be applied recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Bourassa committed May 29, 2015
1 parent 1b0b7b7 commit 4b80f2f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var get = Ember.get;
var forEach = Ember.EnumerableUtils.forEach;
var isArray = Ember.isArray;
var camelize = Ember.String.camelize;

/**
Expand Down Expand Up @@ -345,6 +346,36 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
}
},

/**
Normalize embedded records errors
@method normalizeRelationshipErrors
@private
*/
normalizeRelationshipErrors: function(typeClass, hash) {
if (!this.keyForRelationship) {
return;
}
this._super(typeClass, hash);

var store = this.get('store');
typeClass.eachRelationship(function(key, relationship) {
if (!hash || !hash[key] || !this.hasSerializeRecordsOption(key)) {
return;
}

var relationshipSerializer = store.serializerFor(relationship.type);
if (relationship.kind === 'hasMany' && isArray(hash[key])) {
forEach(hash[key], function(hash) {
if (hash) {
relationshipSerializer.normalizeErrors(relationship.type, hash);
}
});
} else {
relationshipSerializer.normalizeErrors(relationship.type, hash[key]);
}
}, this);
},

// checks config for attrs option to embedded (always) - serialize and deserialize
hasEmbeddedAlwaysOption: function (attr) {
var option = this.attrsOption(attr);
Expand Down

0 comments on commit 4b80f2f

Please sign in to comment.