Reputation: 4342
I am wondering if and how I can do something like below in Sails. Basically, I am trying to handle complex validations - I have a Client model and ContactPerson model. The Client model has ContactPersons nested inside it, and I want to validate that they are all correct before continuing.
// client.js
module.exports = {
attributes: {
name: {
type: 'string',
required: true
}
},
beforeValidation: function(values, cb) {
values.contactPerson.forEach( function( person ) {
var contactPerson = new sails.model.person( person );
var results = contactPerson.validate();
// If valid, continue
// if not valid, invalidate the client Model (cause validationerror)
});
}
}
Upvotes: 0
Views: 120