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

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() { ...@@ -1596,6 +1596,7 @@ module.exports = (function() {
* @param {Array} [options.fields] Fields to update (defaults to all fields) * @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.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.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.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 {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) * @param {Number} [options.limit] How many rows to update (only for mysql and mariadb)
...@@ -1615,7 +1616,8 @@ module.exports = (function() { ...@@ -1615,7 +1616,8 @@ module.exports = (function() {
hooks: true, hooks: true,
individualHooks: false, individualHooks: false,
returning: false, returning: false,
force: false force: false,
persistSideEffects: true
}, options || {}); }, options || {});
options.type = QueryTypes.BULKUPDATE; options.type = QueryTypes.BULKUPDATE;
...@@ -1650,6 +1652,11 @@ module.exports = (function() { ...@@ -1650,6 +1652,11 @@ module.exports = (function() {
var build = self.build(values); var build = self.build(values);
build.set(self._timestampAttributes.updatedAt, values[self._timestampAttributes.updatedAt], { raw: true }); 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 // We want to skip validations for all other fields
options.skip = Utils._.difference(Object.keys(self.attributes), Object.keys(values)); options.skip = Utils._.difference(Object.keys(self.attributes), Object.keys(values));
return build.hookValidate(options).then(function(attributes) { 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!