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

Commit 95901aba by Gabe Gorelick Committed by Sushant

fix(model/increment): properly map fields for attributes in `by` options (#8363)

1 parent c22f8214
Showing with 19 additions and 2 deletions
......@@ -2882,9 +2882,11 @@ class Model {
increment: true
});
const where = _.extend({}, options.where);
Utils.mapOptionFieldNames(options, this);
const where = _.extend({}, options.where);
let values = {};
if (Utils._.isString(fields)) {
values[fields] = options.by;
} else if (Utils._.isArray(fields)) {
......
......@@ -2742,7 +2742,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.User = this.sequelize.define('User', {
id: { type: DataTypes.INTEGER, primaryKey: true },
aNumber: { type: DataTypes.INTEGER },
bNumber: { type: DataTypes.INTEGER }
bNumber: { type: DataTypes.INTEGER },
cNumber: { type: DataTypes.INTEGER, field: 'c_number'}
});
const self = this;
......@@ -2759,6 +2760,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
id: 3,
aNumber: 0,
bNumber: 0
}, {
id: 4,
aNumber: 0,
bNumber: 0,
cNumber: 0
}]);
});
});
......@@ -2774,6 +2780,15 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('uses correct column names for where conditions', function() {
const self = this;
return this.User.increment(['aNumber'], {by: 2, where: {cNumber: 0}}).then(() => {
return self.User.findById(4).then(user4 => {
expect(user4.aNumber).to.be.equal(2);
});
});
});
it('should still work right with other concurrent increments', function() {
const self = this;
return this.User.findAll().then(aUsers => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!