Skip to content

Instantly share code, notes, and snippets.

@robneville73
Created March 30, 2016 20:21
Show Gist options
  • Save robneville73/49eb98d99c3f08710e90f9ef74439451 to your computer and use it in GitHub Desktop.
Save robneville73/49eb98d99c3f08710e90f9ef74439451 to your computer and use it in GitHub Desktop.
_extractRelationshipErrors: function(store, typeClass, payload) {
var relationshipNames = Ember.get(typeClass, 'relationshipNames'); //returns obj with key hasMany and belongsTo arrays of names.
var relationshipsByName = Ember.get(typeClass, 'relationshipsByName'); //returns object with key, kind, and typeClass
var relationTypes = ['hasMany', 'belongsTo'];
relationTypes.forEach(function(relationType) {
relationshipNames[relationType].forEach(function(relationshipName) {
var relationship = relationshipsByName.get(relationshipName);
if (payload.hasOwnProperty(relationshipName)) {
for (var i = 0; i < payload[relationshipName].length; i++) {
//have to get the real id here so that _internalModelForId can find it.
//at this stage, payload is raw server response.
var relatedModel = store.modelFor(relationship.type);
var relatedHash = payload[relationshipName][i];
var relatedId = this.generateId(relatedModel, relatedHash);
this.extractErrors(store, relatedModel, relatedHash, relatedId);
}
}
}, this);
}, this);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment