我寻求这种性质的东西
//validation rules in model "User"
attributes: {
age: {
required: true,
type: 'numeric'
}
},
//now in controller, i want to be able to do this
Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'});
问题是,它不起作用..它提示 beforeValidate 不可用,等等
最佳答案
您需要将回调传递给.validate
:
Recipe.validate({age: 'blah'}, function(err){
if (err && err.invalidAttributes) {
console.log(err.invalidAttributes);
} else {
// model is valid
}
});
关于javascript - 如何仅验证记录而不保存在 Node js 中?风 sails js |吃水线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25824967/