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

Commit 5c5cb18a by Mick Hansen

feat(instance): .save (when an update) will now use an intersection of changed a…

…nd attributes as fields
1 parent cde5de93
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
- When using `Model#find()` with an `order` clause, the table name is prepended to the `ORDER BY` SQL. e.g. `ORDER BY Task.id` rather than `ORDER BY id`. The change is to avoid ambiguous column names where there are eager-loaded associations with the same column names. A side effect is that code like `Task.findAll( { include: [ User ], order: [ [ 'Users.id', 'ASC' ] ] } )` will now throw an error. This should be achieved with `Task.findAll( { include: [ User ], order: [ [ User, 'id', 'ASC' ] ] } )` instead. - When using `Model#find()` with an `order` clause, the table name is prepended to the `ORDER BY` SQL. e.g. `ORDER BY Task.id` rather than `ORDER BY id`. The change is to avoid ambiguous column names where there are eager-loaded associations with the same column names. A side effect is that code like `Task.findAll( { include: [ User ], order: [ [ 'Users.id', 'ASC' ] ] } )` will now throw an error. This should be achieved with `Task.findAll( { include: [ User ], order: [ [ User, 'id', 'ASC' ] ] } )` instead.
- Nested HSTORE objects are no longer supported. Use DataTypes.JSON instead. - Nested HSTORE objects are no longer supported. Use DataTypes.JSON instead.
- In PG `where: { arr: [1, 2] }` where the `arr` column is an array will now use strict comparison (`=`) instead of the overlap operator (`&&`). To obtain the old behaviour, use ` where: { arr: { overlap: [1, 2] }}` - In PG `where: { arr: [1, 2] }` where the `arr` column is an array will now use strict comparison (`=`) instead of the overlap operator (`&&`). To obtain the old behaviour, use ` where: { arr: { overlap: [1, 2] }}`
- The default `fields` for `Instance#save` (when not a new record) is now an intersection of the model attributes and the changed attributes making saves more atomic while still allowing only defined attributes.
# 2.0.0-rc2 # 2.0.0-rc2
- [FEATURE] Added to posibility of using a sequelize object as key in `sequelize.where`. Also added the option of specifying a comparator - [FEATURE] Added to posibility of using a sequelize object as key in `sequelize.where`. Also added the option of specifying a comparator
......
...@@ -459,7 +459,11 @@ module.exports = (function() { ...@@ -459,7 +459,11 @@ module.exports = (function() {
}, options, deprecated); }, options, deprecated);
if (!options.fields) { if (!options.fields) {
options.fields = Object.keys(this.Model.attributes); if (this.isNewRecord) {
options.fields = Object.keys(this.Model.attributes);
} else {
options.fields = _.intersection(this.changed(), Object.keys(this.Model.attributes));
}
} }
if (options.returning === undefined) { if (options.returning === undefined) {
......
...@@ -205,8 +205,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -205,8 +205,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should allow me to disable some of the timestamp fields', function(done) { it('should allow me to disable some of the timestamp fields', function() {
var UpdatingUser = this.sequelize.define('UpdatingUser', {}, { var UpdatingUser = this.sequelize.define('UpdatingUser', {
name: DataTypes.STRING
}, {
timestamps: true, timestamps: true,
updatedAt: false, updatedAt: false,
createdAt: false, createdAt: false,
...@@ -214,20 +216,24 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -214,20 +216,24 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
paranoid: true paranoid: true
}) })
UpdatingUser.sync({force: true}).success(function() { return UpdatingUser.sync({force: true}).then(function() {
UpdatingUser.create().success(function (user) { return UpdatingUser.create({
name: 'heyo'
}).then(function (user) {
expect(user.createdAt).not.to.exist expect(user.createdAt).not.to.exist
expect(user.false).not.to.exist // because, you know we might accidentally add a field named 'false' expect(user.false).not.to.exist // because, you know we might accidentally add a field named 'false'
user.save().success(function (user) {
user.name = 'heho';
return user.save().then(function (user) {
expect(user.updatedAt).not.to.exist expect(user.updatedAt).not.to.exist
user.destroy().success(function(user) { return user.destroy().then(function(user) {
expect(user.deletedAtThisTime).to.exist expect(user.deletedAtThisTime).to.exist
done()
}) });
}) });
}) });
}) });
}) });
it('should allow me to override updatedAt, createdAt, and deletedAt fields with underscored being true', function(done) { it('should allow me to override updatedAt, createdAt, and deletedAt fields with underscored being true', function(done) {
var UserTable = this.sequelize.define('UserCol', { var UserTable = this.sequelize.define('UserCol', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!