Sequelize.js updateAttributes 不保存部分数据
Sequelize.js updateAttributes does not save partial 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));
});
我猜您想将更新后的数据传递给下一个中间件。但是你用了res.send(updated)
。它终止中间件和 return 响应。
您可以使用以下方式传递更新的数据;
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
.
下一个中间件中的数据
希望有用。
我发现问题是因为我使用 beforeValidate
方法显式设置了对象属性。通过删除它,我能够更新该字段。
部分更新数据时,数据不会持久化。例如,我调用以下内容(其中数据是一个对象):
account.updateAttributes(data).then(function(updated) {
res.send(updated);
return next();
})['catch'](function(err) {
log.error(err);
return next(new restify.InternalError(err.message));
});
我猜您想将更新后的数据传递给下一个中间件。但是你用了res.send(updated)
。它终止中间件和 return 响应。
您可以使用以下方式传递更新的数据;
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
.
希望有用。
我发现问题是因为我使用 beforeValidate
方法显式设置了对象属性。通过删除它,我能够更新该字段。