不要怂,就是干,撸起袖子干!

Commit 3f6100e6 by Mick Hansen

Merge pull request #5324 from tornillo/issue5275

Fix model update with individualHooks
2 parents ae89e846 226cb237
Showing with 19 additions and 1 deletions
......@@ -2538,10 +2538,12 @@ Model.prototype.update = function(values, options) {
instances = _instances;
if (!different) {
var keys = Object.keys(changedValues);
// Hooks do not change values or change them uniformly
if (Object.keys(changedValues).length) {
if (keys.length) {
// Hooks change values - record changes in valuesUse so they are executed
valuesUse = changedValues;
options.fields = Utils._.union(options.fields, keys);
}
return;
} else {
......
......@@ -1050,6 +1050,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it('should properly set data when individualHooks are true', function() {
var self = this;
self.User.beforeUpdate(function(instance) {
instance.set('intVal', 1);
});
return self.User.create({ username: 'Peter' }).then(function (user) {
return self.User.update({ data: 'test' }, { where: { id: user.id }, individualHooks: true }).then(function () {
return self.User.findById(user.id).then(function (userUpdated){
expect(userUpdated.intVal).to.be.equal(1);
});
});
});
});
it('sets updatedAt to the current timestamp', function() {
var data = [{ username: 'Peter', secretValue: '42' },
{ username: 'Paul', secretValue: '42' },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!