Skip to content

Instantly share code, notes, and snippets.

@gustaff-weldon
Created July 29, 2016 09:06
Show Gist options
  • Save gustaff-weldon/307e6aeb2ba4d22be9eeeec9990a4913 to your computer and use it in GitHub Desktop.
Save gustaff-weldon/307e6aeb2ba4d22be9eeeec9990a4913 to your computer and use it in GitHub Desktop.
Setting errors on nested model
document.save()
.then(() => {
... some succcess logic handler ...
})
.catch((error) => {
// mark propertiesModel as invalid - pass errors from server
if (Ember.typeOf(error.errors) === 'array') {
let store, modelClass, serverErrors, propertiesServerErrors
store = this.get('store')
modelClass = store.modelFor('document')
serverErrors = store.serializerFor('document').extractErrors(store, modelClass, error, currentDocument.id)
propertiesServerErrors = extractPropertiesErrors(serverErrors)
let propertiesModelErrors = currentDocument.get('propertiesModel.errors')
for (let attributeName in propertiesServerErrors) {
if (propertiesServerErrors.hasOwnProperty(attributeName)) {
propertiesModelErrors.add(attributeName, propertiesServerErrors[attributeName])
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment