2016-06-21 61 views

回答

1

只要发生错误,脚本执行就会停止。

http://docs.sequelizejs.com/en/latest/docs/models-definition/,Sequelize.js的作者举这个例子:

var ValidateMe = sequelize.define('foo', { 
    foo: { 
    type: Sequelize.STRING, 
    validate: { 
     // custom validations are also possible: 
     isEven: function(value) { 
     if(parseInt(value) % 2 != 0) { 
      // This error will stop code execution and give you the chance to catch and handle the error 
      throw new Error('Only even values are allowed!') 
     // we also are in the model's context here, so this.otherField 
     // would get the value of otherField if it existed 
     } 
     } 
    } 
    } 
}); 
相关问题