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

Commit 822c5934 by sdepold

don't update updatedAt attribute if timestamps is false

1 parent 8a3207ff
Showing with 29 additions and 2 deletions
# v1.3.6 #
- [BUG] don't update an existing updatedAt-attribute if timestamps option for a DAO is false
# v1.3.5 # # v1.3.5 #
- [BUT] fixed missed DAO renaming in migrations (thanks to nov) - [BUG] fixed missed DAO renaming in migrations (thanks to nov)
# v1.3.4 # # v1.3.4 #
- [REFACTORING] renamed Model/ModelFactory/ModelFactoryManager to DAO/DAOFactory/DAOFactoryManager - [REFACTORING] renamed Model/ModelFactory/ModelFactoryManager to DAO/DAOFactory/DAOFactoryManager
......
...@@ -83,7 +83,7 @@ module.exports = (function() { ...@@ -83,7 +83,7 @@ module.exports = (function() {
DAO.prototype.save = function() { DAO.prototype.save = function() {
var updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt' var updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt'
if(this.hasOwnProperty(updatedAtAttr)) if(this.__options.timestamps && this.hasOwnProperty(updatedAtAttr))
this[updatedAtAttr] = new Date() this[updatedAtAttr] = new Date()
if(this.isNewRecord) { if(this.isNewRecord) {
......
...@@ -374,6 +374,30 @@ describe('DAO', function() { ...@@ -374,6 +374,30 @@ describe('DAO', function() {
}, 10) }, 10)
}) })
}) })
describe('without timestamps option', function() {
var User2 = sequelize.define('User2', {
username: Sequelize.STRING,
updatedAt: Sequelize.DATE
}, {
timestamps: false
})
beforeEach(function() {
Helpers.async(function(done) {
User2.sync({ force: true }).success(done)
})
})
it("doesn't update the updatedAt column", function() {
Helpers.async(function(done) {
User2.create({ username: 'john doe' }).success(function(johnDoe) {
expect(johnDoe.updatedAt).toBeNull()
done()
})
})
})
})
}) })
describe('updateAttributes', function() { describe('updateAttributes', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!