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

You need to sign in or sign up before continuing.
Commit 21a31906 by Ben Stephenson

Allowed option to persist side effects of virtual setters during an update

1 parent 941b36b2
Showing with 8 additions and 1 deletions
......@@ -1596,6 +1596,7 @@ module.exports = (function() {
* @param {Array} [options.fields] Fields to update (defaults to all fields)
* @param {Boolean} [options.validate=true] Should each row be subject to validation before it is inserted. The whole insert will fail if one row fails validation
* @param {Boolean} [options.hooks=true] Run before / after bulk update hooks?
* @param {Boolean} [options.persistSideEffects=true] Whether or not to update the side effects of any virtual setters.
* @param {Boolean} [options.individualHooks=false] Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks
* @param {Boolean} [options.returning=false] Return the affected rows (only for postgres)
* @param {Number} [options.limit] How many rows to update (only for mysql and mariadb)
......@@ -1615,7 +1616,8 @@ module.exports = (function() {
hooks: true,
individualHooks: false,
returning: false,
force: false
force: false,
persistSideEffects: true
}, options || {});
options.type = QueryTypes.BULKUPDATE;
......@@ -1650,6 +1652,11 @@ module.exports = (function() {
var build = self.build(values);
build.set(self._timestampAttributes.updatedAt, values[self._timestampAttributes.updatedAt], { raw: true });
if ( options.persistSideEffects ) {
values = Utils._.assign(values, Utils._.pick(build.get(), build.changed()));
options.fields = Utils._.union(options.fields, Object.keys(values));
}
// We want to skip validations for all other fields
options.skip = Utils._.difference(Object.keys(self.attributes), Object.keys(values));
return build.hookValidate(options).then(function(attributes) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!