【问题标题】:Sequelize update does not work anymore: "Missing where attribute in the options parameter passed to update"Sequelize 更新不再起作用:“传递给更新的选项参数中缺少 where 属性”
【发布时间】:2014-12-22 06:52:34
【问题描述】:

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 属性”。 文档还提到不推荐使用这种用法。看到这个错误让我想,他们已经改变了它。我做错了什么?

【问题讨论】:

  • 您的链接未链接到文档
  • 谢谢@J.Kirk。 - 修复!它在某个时候是正确的链接(很久以前):/

标签: javascript node.js sequelize.js


【解决方案1】:

显然,文档尚未更新。但表格的wherethe Model.update API docs 建议在您的选择前加上where,如下所示:

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

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

而且它有效!

更新:

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

【讨论】:

  • 这属于他们的迁移指南。
  • 我想知道为什么文档中没有这么重要的信息。也许我不应该使用sequelize?
  • @SoichiHayashi 实际上,它已经添加到文档中一段时间​​了。我用链接更新了我的答案:)
猜你喜欢
  • 1970-01-01
  • 2018-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-09
相关资源
最近更新 更多