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

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
- [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
- [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
if (this.$options && this.$options.include && this.$options.includeNames.indexOf(key) !== -1) {
// Pass it on to the include handler
this._setInclude(key, value, options);
return;
return this;
} else {
// Bunch of stuff we won't do when its raw
if (!options.raw) {
......@@ -327,17 +327,17 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
this.changed(key.split('.')[0], true);
}
}
return;
return this;
}
// If attempting to set primary key and primary key is already defined, return
if (this.Model._hasPrimaryKeys && originalValue && this.Model._isPrimaryKey(key)) {
return;
return this;
}
// If attempting to set read only attributes, return
if (!this.isNewRecord && this.Model._hasReadOnlyAttributes && this.Model._isReadOnlyAttribute(key)) {
return;
return this;
}
// Convert date fields to real date objects
......@@ -349,7 +349,7 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
originalValue = new Date(originalValue);
}
if (originalValue && value.getTime() === originalValue.getTime()) {
return;
return this;
}
}
}
......@@ -693,8 +693,8 @@ Instance.prototype.save = function(options) {
return result;
})
.tap(function() {
if (!wasNewRecord) return;
if (!self.$options.include || !self.$options.include.length) return;
if (!wasNewRecord) return self;
if (!self.$options.include || !self.$options.include.length) return self;
// Nested creation for HasOne/HasMany/BelongsToMany relations
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!