Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize.js updateAttributes does not save partial data

When updating data partially, data does not persist. For example, I call the following (where data is an object):

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

})['catch'](function(err) {
       log.error(err);
           return next(new restify.InternalError(err.message));
});
like image 380
Nick Parsons Avatar asked May 16 '26 15:05

Nick Parsons


1 Answers

I guess you want to pass updated data to next middleware. But you used res.send(updated). It terminates middleware and return the response.

You can use to pass the updated data with the following;

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

So you can attach the updated data to your request object and send with it to next middleware. And you can use the data in next middleware with req.updatedAccount.

I hope it works.

like image 50
Ali BARIN Avatar answered May 18 '26 03:05

Ali BARIN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!