Sequelize update 不再起作用:“在传递给 update 的选项参数中缺少 where 属性"

2022-01-19 00:00:00 node.js javascript sequelize.js

官方 API 文档 建议像这样使用 Model.update:

var gid = ...;
var uid = ...;

var values = { gid: gid };
var where = { uid: uid };
myModel.update(values, where)
.then(function() {
    // update callback
});

但这给了我:传递给更新的选项参数中缺少 where 属性".文档还提到不推荐使用这种用法.看到这个错误让我想,他们已经改变了它.我做错了什么?

But this gives me: "Missing where attribute in the options parameter passed to update". The docs also mention that this usage is deprecated. Seeing this error makes me think, they already changed it. What am I doing wrong?

推荐答案

显然,文档还没有更新.但是 where 行">Model.update API 文档 建议在您的选择前加上 where,如下所示:

Apparently, the docs have not been updated yet. But the table's where row of the Model.update API docs suggests prefixing your selection with where, like so:

var gid = ...;
var uid = ...;

var values = { gid: gid };
var selector = { 
  where: { uid: uid }
};
myModel.update(values, selector)
.then(function() {
    // update callback
});

而且它有效!

更新:

文档已更新(文档也已移动).查看 docs.sequelize.com 上的 Model.update.请注意,options.where 不是可选的(它不在括号 [] 中).

The docs have since been updated (and the docs have also been moved). Check out Model.update on docs.sequelize.com. Note that options.where is not optional (it is not in brackets []).

相关文章