使用自定义模型验证器检查模型中的记录时。价差内的回报似乎并没有结束控制流。
//Post.js Model
/**
* Custom Validator
**/
types: {
isUserValid: function(user_id) {
var Promise = require('bluebird');
Promise.all([
User.findOne({id: user_id})
])
.spread(function(user) {
console.log(user);
if (user === null || user === undefined) {
console.log('failed');
return false;
}else{
console.log('passed');
return true;
}
});
}
},
我的回复是标准验证失败回复。
{
"error": "E_VALIDATION",
"status": 400,
"summary": "1 attribute is invalid",
"model": "Post",
"invalidAttributes": {
"owner": [
{
"rule": "isUserValid",
"message": "\"isUserValid\" validation rule failed for input: 1"
}
]
}
}