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

Commit 7370a098 by Mick Hansen

Merge pull request #4138 from sequelize/fix-update-set-options

update should pass options to set
2 parents e368ce68 e37f3340
Showing with 6 additions and 3 deletions
...@@ -770,12 +770,15 @@ Instance.prototype.hookValidate = function(options) { ...@@ -770,12 +770,15 @@ Instance.prototype.hookValidate = function(options) {
Instance.prototype.update = function(values, options) { Instance.prototype.update = function(values, options) {
var changedBefore = this.changed() || [] var changedBefore = this.changed() || []
, sideEffects , sideEffects
, fields; , fields
, setOptions;
options = options || {}; options = options || {};
if (Array.isArray(options)) options = {fields: options}; if (Array.isArray(options)) options = {fields: options};
this.set(values, {attributes: options.fields}); setOptions = this.$Model.$optClone(options);
setOptions.attributes = options.fields;
this.set(values, setOptions);
// Now we need to figure out which fields were actually affected by the setter. // Now we need to figure out which fields were actually affected by the setter.
sideEffects = _.without.apply(this, [this.changed() || []].concat(changedBefore)); sideEffects = _.without.apply(this, [this.changed() || []].concat(changedBefore));
......
...@@ -285,7 +285,7 @@ var conformOptions = function(options, self) { ...@@ -285,7 +285,7 @@ var conformOptions = function(options, self) {
}); });
}; };
var optClone = Model.prototype.__optClone = function(options) { var optClone = Model.prototype.__optClone = Model.prototype.$optClone = function(options) {
options = options || {}; options = options || {};
return Utils.cloneDeep(options, function(elem) { return Utils.cloneDeep(options, function(elem) {
// The InstanceFactories used for include are pass by ref, so don't clone them. // The InstanceFactories used for include are pass by ref, so don't clone them.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!