I am trying to create server-side validations for nested models. Here are my Ember models:
//models/blog.js
export default DS.Model.extend({
"name": DS.attr('string'),
"category": DS.belongsTo('category'),
"posts": DS.hasMany('post')
});
//models/category.js
export default DS.Model.extend({
"name": DS.attr('string')
});
//models/post.js
export default DS.Model.extend({
"text": DS.attr('string')
});
When saving blog model, I validate all the child models as well.
How should I format ember-friendly error JSON when there is a validation error on one of the child models' attribute?
this is a JSON I produce right now when blog's title is invalid:
{
"errors": [
{
"title": "name",
"detail": "some error"
}
]
}
Aucun commentaire:
Enregistrer un commentaire