想象一下,我已经定义了以下自定义验证器函数:
isUnique: function () { // This works as expected
throw new Error({error:[{message:'Email address already in use!'}]});
}
但是,当我尝试查询数据库时,我遇到了问题:
isUnique: function (email) { // This doesn't work
var User = seqeulize.import('/path/to/user/model');
User.find({where:{email: email}})
.success(function () { // This gets called
throw new Error({error:[{message:'Email address already in use!'}]}); // But this isn't triggering a validation error.
});
}
如何在自定义验证器中查询 ORM 并根据 ORM 的响应触发验证错误?