dimanche 22 mars 2015

Validations for associative models sailsJs


I am trying to build a REST API on sailsjs v0.11.0, I am looking for a way to validate all POST requests. Validation works for simple models.


Simple model example: category.js



module.exports = {
attributes: {
name: {
type: 'string',
required: true, // this works
unique: true
}
}
}


Associative one to many model example where validation doesnt work:


Chapter.js



module.exports = {

attributes: {
name: 'string',
categoryId: 'integer',
pages: {
type: 'string',
required: true // This doesnt work
},
owner: {
model: 'Upload'
}
}

};


Upload.js



module.exports = {

attributes: {
draftId: 'integer',
chapters: {
collection: 'Chapter',
via: 'owner'
}
}
};




Aucun commentaire:

Enregistrer un commentaire