【问题标题】:Sequelize.js updateAttributes does not save partial dataSequelize.js updateAttributes 不保存部分数据
【发布时间】:2015-08-21 13:41:24
【问题描述】:

部分更新数据时,数据不会持久化。例如,我调用以下内容(其中 data 是一个对象):

account.updateAttributes(data).then(function(updated) {
        res.send(updated);
        return next();

})['catch'](function(err) {
       log.error(err);
           return next(new restify.InternalError(err.message));
});

【问题讨论】:

标签: node.js postgresql sequelize.js


【解决方案1】:

我猜你想将更新的数据传递给下一个中间件。但是你使用了res.send(updated)。它终止中间件并返回响应。

您可以使用以下方式传递更新的数据;

account.updateAttributes(data).then(function(updated) {
  req.updatedAccount = updated;
  return next();
})['catch'](function(err) {
  log.error(err);
  return next(new restify.InternalError(err.message));
});

因此,您可以将更新后的数据附加到您的请求对象,并将其发送到下一个中​​间件。并且您可以在下一个中间件中使用req.updatedAccount 中的数据。

我希望它有效。

【讨论】:

    【解决方案2】:

    我发现问题是因为我使用beforeValidate 方法显式设置对象属性引起的。通过删除它,我能够更新该字段。

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多