如何检查实例更新是否已保存?
How to check if an instance update has been saved?
在 nodes 14.x
中使用 sqeuelizejs 6.5
,对于模型实例,有没有办法检查实例是否已经 saved/updated(类似于 model.saved() in ruby ORM)?这是一个代码示例:
let art = await Artwork.findByPk(req.body.id); //art is an instance of Artwork model
if (!art) return false;
//do some update with instance art, such as :
//art.name = "a new name";
//art.description = "a new description";
//await art.save();
//.....some code here
if (art.saved()) {. //<<==is there art.saved()/art.updated() to check if the instance update has been saved?
//do something
} else {
//if art not updated, do something else
}
if(art.changed()) { // need save
} else {
// no updated
}
在 nodes 14.x
中使用 sqeuelizejs 6.5
,对于模型实例,有没有办法检查实例是否已经 saved/updated(类似于 model.saved() in ruby ORM)?这是一个代码示例:
let art = await Artwork.findByPk(req.body.id); //art is an instance of Artwork model
if (!art) return false;
//do some update with instance art, such as :
//art.name = "a new name";
//art.description = "a new description";
//await art.save();
//.....some code here
if (art.saved()) {. //<<==is there art.saved()/art.updated() to check if the instance update has been saved?
//do something
} else {
//if art not updated, do something else
}
if(art.changed()) { // need save
} else {
// no updated
}