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

Commit 54b9cf37 by Jan Aagaard Meier

Move all calls to mapFieldNames to Utils

1 parent ff8a672f
Showing with 6 additions and 46 deletions
......@@ -716,7 +716,7 @@ module.exports = (function() {
if (options.attributes === undefined) {
options.attributes = Object.keys(this.tableAttributes);
}
mapFieldNames.call(this, options, this);
Utils.mapOptionFieldNames(options, this);
options = paranoidClause(this, options);
......@@ -838,7 +838,7 @@ module.exports = (function() {
validateIncludedElements.call(this, options);
}
mapFieldNames.call(this, options, this);
Utils.mapOptionFieldNames(options, this);
options.dataType = DataTypes.INTEGER;
options.includeIgnoreAttributes = false;
......@@ -1442,7 +1442,7 @@ module.exports = (function() {
options.type = QueryTypes.BULKDELETE;
mapFieldNames.call(this, options, this);
Utils.mapOptionFieldNames(options, this);
return Promise.try(function() {
// Run before hook
......@@ -1513,7 +1513,7 @@ module.exports = (function() {
var self = this
, instances;
mapFieldNames.call(this, options, this);
Utils.mapOptionFieldNames(options, this);
return Promise.try(function() {
// Run before hook
......@@ -1697,7 +1697,7 @@ module.exports = (function() {
}
});
mapFieldNames.call(self, options, self);
Utils.mapOptionFieldNames(options, self);
// Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) {
......@@ -1747,46 +1747,6 @@ module.exports = (function() {
}
};
var mapFieldNames = function(options, Model) {
if (options.attributes) {
options.attributes = options.attributes.map(function(attr) {
// Object lookups will force any variable to strings, we don't want that for special objects etc
if (typeof attr !== "string") return attr;
// Map attributes to aliased syntax attributes
if (Model.rawAttributes[attr] && attr !== Model.rawAttributes[attr].field) {
return [Model.rawAttributes[attr].field, attr];
}
return attr;
});
}
if (options.where) {
var attributes = options.where
, attribute
, rawAttribute;
if (options.where instanceof Utils.and || options.where instanceof Utils.or) {
attributes = undefined;
options.where.args = options.where.args.map(function (where) {
return mapFieldNames({
where: where
}, Model).where;
});
}
if (attributes) {
for (attribute in attributes) {
rawAttribute = Model.rawAttributes[attribute];
if (rawAttribute && rawAttribute.field !== rawAttribute.fieldName) {
attributes[rawAttribute.field] = attributes[attribute];
delete attributes[attribute];
}
}
}
}
return options;
};
// private
// validateIncludedElements should have been called before this method
......@@ -1998,7 +1958,7 @@ module.exports = (function() {
include.attributes = Object.keys(include.model.tableAttributes);
}
include = mapFieldNames(include, include.model);
include = Utils.mapOptionFieldNames(include, include.model);
// pseudo include just needed the attribute logic, return
if (include._pseudo) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!