Javascript 如何创建模型实例并验证它,而不将其保存到Sails中的DB?

Javascript 如何创建模型实例并验证它,而不将其保存到Sails中的DB?,javascript,sails.js,Javascript,Sails.js,我想知道我是否可以,如何在船帆上做类似的事情。基本上,我正在尝试处理复杂的验证——我有一个客户机模型和联系人模型。客户端模型中嵌套了ContactPerson,我想在继续之前验证它们是否都正确 // client.js module.exports = { attributes: { name: { type: 'string', required: true } }, beforeValidation: function(values,

我想知道我是否可以,如何在船帆上做类似的事情。基本上,我正在尝试处理复杂的验证——我有一个客户机模型和联系人模型。客户端模型中嵌套了ContactPerson,我想在继续之前验证它们是否都正确

// 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)
    });
  }
}
// if not valid
if(err) return cb(err);
// if valid
cb();