The official API documentation建议像这样使用 Model.update:
var gid = ...;
var uid = ...;
var values = { gid: gid };
var where = { uid: uid };
myModel.update(values, where)
.then(function() {
// update callback
});
但这给了我:“传递给更新的选项参数中缺少 where 属性”。 文档还提到这种用法已被弃用。看到这个错误让我想,他们已经改变了它。我做错了什么?
最佳答案
显然,文档还没有更新。但是表的 where 行 the Model.update API docs建议在您的选择前加上 where 前缀,如下所示:
var gid = ...;
var uid = ...;
var values = {
gid
};
var selector = {
where: {
uid
}
};
await myModel.update(values, selector);
// done!
而且有效!
更新:
文档已更新(文档也已移动)。查看Model.update on docs.sequelize.com .请注意,options.where 不是可选的(它不在方括号 [] 中)。
关于javascript - Sequelize 更新不再起作用 : "Missing where attribute in the options parameter passed to update",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26581715/