sequelize
是否有办法检查模型是否已更改?例如
var user = User.findOne(where:{email:'test@user.com'}).then(user=>{
if(some_condition)user.email = 'changed@email.com'
//can I do something like this to check if model has been changed? before the save action?
if(user.dirty){}
})
答案 0 :(得分:1)
Sequelize在模型实例级别确实有一个更改的方法,但是这会将当前值与_previousDataValues
进行比较。
已记录here
可以用作
Model.testModel.findById(23)
.then(instance => {
instance.name = "new Name";
console.log(instance.changed());
// This should log [name] and would be false if nothing was changed.
})