本文介绍了Sequelize 更新不再起作用:“传递给更新的选项参数中缺少 where 属性"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方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?

推荐答案

显然,文档尚未更新.但是表的 whereModel.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 []).

这篇关于Sequelize 更新不再起作用:“传递给更新的选项参数中缺少 where 属性"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:11