是否可能有一个使用Sequelize.js的异步验证器?在保存模型之前,我想检查是否存在关联。就像这样:
User = db.define("user", {
name: Sequelize.STRING
},
{
validate:
hasDevice: ->
@getDevices().success (devices) ->
throw Exception if (devices.length < 1)
return
})
# .... Device is just another model
User.hasMany(Device)还是有一种强制检查同步运行的方法?(不理想)
发布于 2013-10-29 06:27:22
您可以在v2.0.0中使用异步验证。它的工作方式如下:
var Model = sequelize.define('Model', {
attr: Sequelize.STRING
}, {
validate: {
hasAssociation: function(next) {
functionThatChecksTheAssociation(function(ok) {
if (ok) {
next()
} else {
next('Ooops. Something is wrong!')
}
})
}
}
})https://stackoverflow.com/questions/19640308
复制相似问题