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

Commit 75b63d86 by Mick Hansen

Merge pull request #5081 from sushantdhiman/fix-4702

Fix(#4702): instance returns this on all paths
2 parents 36794378 71587641
Showing with 8 additions and 7 deletions
# Future # Future
- [FIXED] calling Model.update() modifies passed values [#4520](https://github.com/sequelize/sequelize/issues/4520) - [FIXED] calling Model.update() modifies passed values [#4520](https://github.com/sequelize/sequelize/issues/4520)
- [FIXED] Instance can be chained on .set() and other methods [#4702](https://github.com/sequelize/sequelize/issues/4702)
# 3.15.0 # 3.15.0
- [ADDED] Improve support for pg range type to handle unbound ranges, +/-infinity bounds and empty ranges - [ADDED] Improve support for pg range type to handle unbound ranges, +/-infinity bounds and empty ranges
......
...@@ -314,7 +314,7 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non ...@@ -314,7 +314,7 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
if (this.$options && this.$options.include && this.$options.includeNames.indexOf(key) !== -1) { if (this.$options && this.$options.include && this.$options.includeNames.indexOf(key) !== -1) {
// Pass it on to the include handler // Pass it on to the include handler
this._setInclude(key, value, options); this._setInclude(key, value, options);
return; return this;
} else { } else {
// Bunch of stuff we won't do when its raw // Bunch of stuff we won't do when its raw
if (!options.raw) { if (!options.raw) {
...@@ -327,17 +327,17 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non ...@@ -327,17 +327,17 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
this.changed(key.split('.')[0], true); this.changed(key.split('.')[0], true);
} }
} }
return; return this;
} }
// If attempting to set primary key and primary key is already defined, return // If attempting to set primary key and primary key is already defined, return
if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) { if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) {
return; return this;
} }
// If attempting to set read only attributes, return // If attempting to set read only attributes, return
if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) { if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) {
return; return this;
} }
// Convert date fields to real date objects // Convert date fields to real date objects
...@@ -349,7 +349,7 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non ...@@ -349,7 +349,7 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
originalValue = new Date(originalValue); originalValue = new Date(originalValue);
} }
if (originalValue && value.getTime() === originalValue.getTime()) { if (originalValue && value.getTime() === originalValue.getTime()) {
return; return this;
} }
} }
} }
...@@ -693,8 +693,8 @@ Instance.prototype.save = function(options) { ...@@ -693,8 +693,8 @@ Instance.prototype.save = function(options) {
return result; return result;
}) })
.tap(function() { .tap(function() {
if (!wasNewRecord) return; if (!wasNewRecord) return self;
if (!self.$options.include || !self.$options.include.length) return; if (!self.$options.include || !self.$options.include.length) return self;
// Nested creation for HasOne/HasMany/BelongsToMany relations // Nested creation for HasOne/HasMany/BelongsToMany relations
return Promise.map(self.$options.include.filter(function (include) { return Promise.map(self.$options.include.filter(function (include) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!