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

Commit ec456f59 by Augusto Franzoia

Support silent: true in bulk update

1 parent 4651cfbe
# FUTURE
- [ADDED] Support silent: true in bulk update [#5200](https://github.com/sequelize/sequelize/issues/5200)
# 3.17.3
- [FIXED] Regression with array values from security fix in 3.17.2
......
......@@ -2401,6 +2401,7 @@ Model.prototype.restore = function(options) {
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Boolean} [options.benchmark=false] Print query execution time in milliseconds when logging SQL.
* @param {Transaction} [options.transaction] Transaction to run query under
* @param {Boolean} [options.silent=false] If true, the updatedAt timestamp will not be updated.
*
* @return {Promise<Array<affectedCount,affectedRows>>}
*/
......@@ -2442,7 +2443,7 @@ Model.prototype.update = function(values, options) {
}
}
if (this._timestampAttributes.updatedAt) {
if (this._timestampAttributes.updatedAt && !options.silent) {
values[this._timestampAttributes.updatedAt] = this.$getDefaultTimestamp(this._timestampAttributes.updatedAt) || Utils.now(this.sequelize.options.dialect);
}
......
......@@ -1085,6 +1085,37 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
it('does not update timestamps when passing silent=true in a bulk update', function() {
var self = this
, updatedAtPeter
, updatedAtPaul
, data = [
{ username: 'Paul' },
{ username: 'Peter' }
];
return this.User.bulkCreate(data).then(function() {
return self.User.findAll();
}).then(function(users) {
updatedAtPaul = users[0].updatedAt;
updatedAtPeter = users[1].updatedAt;
})
.then(function() {
return self.sequelize.Promise.delay(150);
})
.then(function() {
return self.User.update(
{ aNumber: 1 },
{ where: {}, silent: true }
);
}).then(function() {
return self.User.findAll();
}).then(function(users) {
expect(users[0].updatedAt).to.equalTime(updatedAtPeter);
expect(users[1].updatedAt).to.equalTime(updatedAtPaul);
});
});
describe('when nothing changed', function() {
beforeEach(function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!