1
我有一个领域模型中的一些少数验证:在Sequelize:如何防止以下验证的执行,如果当前失败
...
someField: {
...
validate: {
someValidator1: true,
someValidator2: true,
}
},
...
两个验证Sequelize是独立地执行。
如何不执行第二个如果第一个失败?
我有一个领域模型中的一些少数验证:在Sequelize:如何防止以下验证的执行,如果当前失败
...
someField: {
...
validate: {
someValidator1: true,
someValidator2: true,
}
},
...
两个验证Sequelize是独立地执行。
如何不执行第二个如果第一个失败?
只要发生错误,脚本执行就会停止。
在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
}
}
}
}
});