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

Commit 0047dca9 by Ali Essam Committed by Sushant

fix(optimistic_locking): increment version attribute with Model.decrement (#8593)

1 parent 2c48c554
...@@ -2926,7 +2926,7 @@ class Model { ...@@ -2926,7 +2926,7 @@ class Model {
options.attributes[updatedAtAttribute.field || updatedAtAttr] = this._getDefaultTimestamp(updatedAtAttr) || Utils.now(this.sequelize.options.dialect); options.attributes[updatedAtAttribute.field || updatedAtAttr] = this._getDefaultTimestamp(updatedAtAttr) || Utils.now(this.sequelize.options.dialect);
} }
if (versionAttr) { if (versionAttr) {
values[versionAttr] = 1; values[versionAttr] = options.increment ? 1 : -1;
} }
for (const attr of Object.keys(values)) { for (const attr of Object.keys(values)) {
......
...@@ -65,5 +65,16 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -65,5 +65,16 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(account.version).to.eq(1); expect(account.version).to.eq(1);
}); });
}); });
it('decrement() also increments the version', () => {
return Account.create({number: 1}).then(account => {
expect(account.version).to.eq(0);
return account.decrement('number', { by: 1} );
}).then(account => {
return account.reload();
}).then(account => {
expect(account.version).to.eq(1);
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!