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

You need to sign in or sign up before continuing.
Commit 160b5eb1 by Jan Aagaard Meier

Merge pull request #6810 from sequelize/fix-6296

2 parents aa5a43ba 18ca53cd
......@@ -12,6 +12,7 @@
- [ADDED] `option.silent` for increment and decrement [#6795](https://github.com/sequelize/sequelize/pull/6795)
- [CHANGED] `now` function allow milliseconds in timestamps on mysql [#6441](https://github.com/sequelize/sequelize/issues/6441)
- [ADDED] `options.rowFormat` added to Query Generator for MySQL dialect using InnoDB engines [#6824] (https://github.com/sequelize/sequelize/issues/6824)
- [FIXED] `Increment` / `Decrement` properly maps to timestamp fields [#6296](https://github.com/sequelize/sequelize/issues/6296)
## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
......
......@@ -3666,6 +3666,7 @@ class Model {
increment(fields, options) {
const identifier = this.where();
const updatedAtAttr = this.constructor._timestampAttributes.updatedAt;
const updatedAtAttribute = this.constructor.rawAttributes[updatedAtAttr];
options = _.defaults({}, options, {
by: 1,
......@@ -3687,7 +3688,7 @@ class Model {
}
if (!options.silent && updatedAtAttr && !values[updatedAtAttr]) {
options.attributes[updatedAtAttr] = this.constructor._getDefaultTimestamp(updatedAtAttr) || Utils.now(this.sequelize.options.dialect);
options.attributes[updatedAtAttribute.field || updatedAtAttr] = this.constructor._getDefaultTimestamp(updatedAtAttr) || Utils.now(this.sequelize.options.dialect);
}
for (const attr of Object.keys(values)) {
......
......@@ -73,17 +73,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
autoIncrement: true,
field: 'commentId'
},
text: {
type: DataTypes.STRING,
field: 'comment_text'
},
notes: {
type: DataTypes.STRING,
field: 'notes'
}
text: { type: DataTypes.STRING, field: 'comment_text' },
notes: { type: DataTypes.STRING, field: 'notes' },
likes: { type: DataTypes.INTEGER, field: 'like_count' },
createdAt: { type: DataTypes.DATE, field: 'created_at', allowNull: false },
updatedAt: { type: DataTypes.DATE, field: 'updated_at', allowNull: false }
}, {
tableName: 'comments',
timestamps: false
timestamps: true
});
this.User.hasMany(this.Task, {
......@@ -145,6 +142,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
},
notes: {
type: DataTypes.STRING
},
like_count: {
type: DataTypes.INTEGER
},
created_at: {
type: DataTypes.DATE,
allowNull: false
},
updated_at: {
type: DataTypes.DATE
}
})
]);
......@@ -231,6 +238,35 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it('increment should work', function() {
return this.Comment.destroy({ truncate: true })
.then(() => this.Comment.create({ note: 'oh boy, here I go again', likes: 23 }))
.then(comment => comment.increment('likes'))
.then(comment => comment.reload())
.then(comment => {
expect(comment.likes).to.be.equal(24);
});
});
it('decrement should work', function() {
return this.Comment.destroy({ truncate: true })
.then(() => this.Comment.create({ note: 'oh boy, here I go again', likes: 23 }))
.then(comment => comment.decrement('likes'))
.then(comment => comment.reload())
.then(comment => {
expect(comment.likes).to.be.equal(22);
});
});
it('sum should work', function() {
return this.Comment.destroy({ truncate: true })
.then(() => this.Comment.create({ note: 'oh boy, here I go again', likes: 23 }))
.then(() => this.Comment.sum('likes'))
.then(likes => {
expect(likes).to.be.equal(23);
});
});
it('should create, fetch and update with alternative field names from a simple model', function() {
var self = this;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!