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

Commit 83ba5dba by Mick Hansen

💄 rename dao to instance

1 parent 110af509
Showing with 24 additions and 24 deletions
......@@ -1624,7 +1624,7 @@ module.exports = (function() {
values[this._timestampAttributes.updatedAt] = this.__getTimestamp(this._timestampAttributes.updatedAt);
}
var daos
var instances
, valuesUse;
return Promise.try(function() {
......@@ -1659,11 +1659,11 @@ module.exports = (function() {
}).then(function() {
valuesUse = values;
// Get daos and run beforeUpdate hook on each record individually
// Get instances and run beforeUpdate hook on each record individually
if (options.individualHooks) {
return self.findAll({where: options.where}, {transaction: options.transaction}).then(function(_daos) {
daos = _daos;
if (!daos.length) {
return self.findAll({where: options.where}, {transaction: options.transaction}).then(function(_instances) {
instances = _instances;
if (!instances.length) {
return [];
}
......@@ -1672,22 +1672,22 @@ module.exports = (function() {
var changedValues
, different = false;
return Promise.map(daos, function(dao) {
return Promise.map(instances, function(instance) {
// Record updates in instances dataValues
Utils._.extend(dao.dataValues, values);
Utils._.extend(instance.dataValues, values);
// Set the changed fields on the instance
Utils._.forIn(valuesUse, function(newValue, attr) {
if (newValue !== dao._previousDataValues[attr]) {
dao.setDataValue(attr, newValue);
if (newValue !== instance._previousDataValues[attr]) {
instance.setDataValue(attr, newValue);
}
});
// Run beforeUpdate hook
return self.runHooks('beforeUpdate', dao, options).then(function() {
return self.runHooks('beforeUpdate', instance, options).then(function() {
if (!different) {
var thisChangedValues = {};
Utils._.forIn(dao.dataValues, function(newValue, attr) {
if (newValue !== dao._previousDataValues[attr]) {
Utils._.forIn(instance.dataValues, function(newValue, attr) {
if (newValue !== instance._previousDataValues[attr]) {
thisChangedValues[attr] = newValue;
}
});
......@@ -1699,10 +1699,10 @@ module.exports = (function() {
}
}
return dao;
return instance;
});
}).then(function(_daos) {
daos = _daos;
}).then(function(_instances) {
instances = _instances;
if (!different) {
// Hooks do not change values or change them uniformly
......@@ -1714,15 +1714,15 @@ module.exports = (function() {
} else {
// Hooks change values in a different way for each record
// Do not run original query but save each record individually
return Promise.map(daos, function(dao) {
return Promise.map(instances, function(instance) {
var individualOptions = Utils._.clone(options);
delete individualOptions.individualHooks;
individualOptions.hooks = false;
individualOptions.validate = false;
return dao.save(individualOptions);
}).tap(function(_daos) {
daos = _daos;
return instance.save(individualOptions);
}).tap(function(_instances) {
instances = _instances;
});
}
});
......@@ -1740,7 +1740,7 @@ module.exports = (function() {
// Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) {
if (options.returning) {
daos = affectedRows;
instances = affectedRows;
return [affectedRows.length, affectedRows];
}
......@@ -1748,10 +1748,10 @@ module.exports = (function() {
});
}).tap(function(result) {
if (options.individualHooks) {
return Promise.map(daos, function(dao) {
return self.runHooks('afterUpdate', dao, options);
return Promise.map(instances, function(instance) {
return self.runHooks('afterUpdate', instance, options);
}).then(function() {
result[1] = daos;
result[1] = instances;
});
}
}).tap(function() {
......@@ -1763,7 +1763,7 @@ module.exports = (function() {
});
}
}).then(function(result) {
// Return result in form [affectedRows, daos] (daos missed off if options.individualHooks != true)
// Return result in form [affectedRows, instances] (instances missed off if options.individualHooks != true)
return result;
});
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!