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

Commit 9906932b by Jan Aagaard Meier

Fix for readonlyattributes when underscored is true. Closes #1523

1 parent c1dc1776
...@@ -8,6 +8,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell ...@@ -8,6 +8,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
- [BUG] Removed the hard dependency on pg, allowing users to use pg.js - [BUG] Removed the hard dependency on pg, allowing users to use pg.js
- [BUG] Fixed a bug with foreign keys pointing to attributes that were not integers. Now your primaryKey can be a string, and associations will still work. Thanks to @fixe [#1544](https://github.com/sequelize/sequelize/pull/1544) - [BUG] Fixed a bug with foreign keys pointing to attributes that were not integers. Now your primaryKey can be a string, and associations will still work. Thanks to @fixe [#1544](https://github.com/sequelize/sequelize/pull/1544)
- [BUG] Fix a case where createdAt timestamp would not be set when updatedAt was disabled Thanks to @fixe [#1543](https://github.com/sequelize/sequelize/pull/1543) - [BUG] Fix a case where createdAt timestamp would not be set when updatedAt was disabled Thanks to @fixe [#1543](https://github.com/sequelize/sequelize/pull/1543)
- [BUG] Fix a case where timestamps were not being write protected in `set` when underscored=true. janmeier [#1523](https://github.com/sequelize/sequelize/pull/1523)
#### Backwards compatability changes #### Backwards compatability changes
......
...@@ -178,7 +178,7 @@ module.exports = (function() { ...@@ -178,7 +178,7 @@ module.exports = (function() {
Util.inherits(this.DAO, DAO); Util.inherits(this.DAO, DAO);
this._readOnlyAttributes = Object.keys(this._timestampAttributes) this._readOnlyAttributes = Utils._.values(this._timestampAttributes)
this._hasReadOnlyAttributes = this._readOnlyAttributes && this._readOnlyAttributes.length this._hasReadOnlyAttributes = this._readOnlyAttributes && this._readOnlyAttributes.length
this._isReadOnlyAttribute = Utils._.memoize(function (key) { this._isReadOnlyAttribute = Utils._.memoize(function (key) {
return self._hasReadOnlyAttributes && self._readOnlyAttributes.indexOf(key) !== -1 return self._hasReadOnlyAttributes && self._readOnlyAttributes.indexOf(key) !== -1
......
...@@ -62,6 +62,24 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -62,6 +62,24 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect(user.get('updatedAt')).not.to.be.ok expect(user.get('updatedAt')).not.to.be.ok
}) })
it('doesn\'t set underscored timestamps', function () {
var User = this.sequelize.define('User', {
identifier: {type: DataTypes.STRING, primaryKey: true}
}, {
underscored: true
})
var user = User.build()
user.set({
created_at: new Date(2000, 1, 1),
updated_at: new Date(2000, 1, 1)
})
expect(user.get('created_at')).not.to.be.ok
expect(user.get('updated_at')).not.to.be.ok
})
it('doesn\'t set value if not a dynamic setter or a model attribute', function() { it('doesn\'t set value if not a dynamic setter or a model attribute', function() {
var User = this.sequelize.define('User', { var User = this.sequelize.define('User', {
name: {type: DataTypes.STRING}, name: {type: DataTypes.STRING},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!