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

Commit bb1d01cb by Jan Aagaard Meier

Set updatedAt timestamp when validations is true in bulkUpdate. Closes #1962

1 parent 10d35177
...@@ -11,6 +11,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -11,6 +11,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Fixed problems with transcation parameter being removed / not passed on in associations [#1789](https://github.com/sequelize/sequelize/issues/1789) and [#1968](https://github.com/sequelize/sequelize/issues/1968) - [BUG] Fixed problems with transcation parameter being removed / not passed on in associations [#1789](https://github.com/sequelize/sequelize/issues/1789) and [#1968](https://github.com/sequelize/sequelize/issues/1968)
- [BUG] Fix problem with minConnections. [#2048](https://github.com/sequelize/sequelize/issues/2048) - [BUG] Fix problem with minConnections. [#2048](https://github.com/sequelize/sequelize/issues/2048)
- [BUG] Fix default scope being overwritten [#2087](https://github.com/sequelize/sequelize/issues/2087) - [BUG] Fix default scope being overwritten [#2087](https://github.com/sequelize/sequelize/issues/2087)
- [BUG] Fixed updatedAt timestamp not being set in bulk create when validate = true. [#1962](https://github.com/sequelize/sequelize/issues/1962)
- [INTERNALS] Replaced lingo with inflection - [INTERNALS] Replaced lingo with inflection
- [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils` - [INTERNALS] Removed underscore.string dependency and moved a couple of helper functions from `Utils._` to `Utils`
- [INTERNALS] Update dependencies - [INTERNALS] Update dependencies
......
...@@ -1376,6 +1376,7 @@ module.exports = (function() { ...@@ -1376,6 +1376,7 @@ module.exports = (function() {
// Validate // Validate
if (options.validate) { if (options.validate) {
var build = self.build(attrValueHash); var build = self.build(attrValueHash);
build.set(self._timestampAttributes.updatedAt, attrValueHash[self._timestampAttributes.updatedAt], { raw: true });
// We want to skip validations for all other fields // We want to skip validations for all other fields
var skippedFields = Utils._.difference(Object.keys(self.attributes), Object.keys(attrValueHash)); var skippedFields = Utils._.difference(Object.keys(self.attributes), Object.keys(attrValueHash));
......
...@@ -860,30 +860,38 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -860,30 +860,38 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('sets updatedAt to the current timestamp', function(done) { it('sets updatedAt to the current timestamp', function() {
var self = this var data = [{ username: 'Peter', secretValue: '42' },
, data = [{ username: 'Peter', secretValue: '42' },
{ username: 'Paul', secretValue: '42' }, { username: 'Paul', secretValue: '42' },
{ username: 'Bob', secretValue: '43' }] { username: 'Bob', secretValue: '43' }];
this.User.bulkCreate(data).success(function() { this.clock = sinon.useFakeTimers();
self.User.update({username: 'Bill'}, {secretValue: '42'}).done(function(err) {
expect(err).not.to.be.ok
self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(3)
expect(users[0].username).to.equal("Bill") return this.User.bulkCreate(data).bind(this).then(function() {
expect(users[1].username).to.equal("Bill") return this.User.findAll({order: 'id'});
expect(users[2].username).to.equal("Bob") }).then(function (users) {
this.updatedAt = users[0].updatedAt;
expect(parseInt(+users[0].updatedAt/5000, 10)).to.be.closeTo(parseInt(+new Date()/5000, 10), 1) expect(this.updatedAt).to.be.ok;
expect(parseInt(+users[1].updatedAt/5000, 10)).to.be.closeTo(parseInt(+new Date()/5000, 10), 1) expect(this.updatedAt).to.equalTime(users[2].updatedAt); // All users should have the same updatedAt
done() // Pass the time so we can actually see a change
}) this.clock.tick(1000);
})
}) return this.User.update({username: 'Bill'}, {secretValue: '42'});
}) }).then(function () {
return this.User.findAll({order: 'id'});
}).then(function (users) {
expect(users[0].username).to.equal("Bill");
expect(users[1].username).to.equal("Bill");
expect(users[2].username).to.equal("Bob");
expect(users[0].updatedAt).to.be.afterTime(this.updatedAt);
expect(users[2].updatedAt).to.equalTime(this.updatedAt);
this.clock.restore();
});
});
it('returns the number of affected rows', function(_done) { it('returns the number of affected rows', function(_done) {
var self = this var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!