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

Commit f346681d by Thaddeus Quintin

Inserted options to all getTableName calls. This allows overriding getTableName …

…and constructing dynamic tablenames based on specific options.
1 parent 4fadfb07
Showing with 12 additions and 12 deletions
......@@ -81,7 +81,7 @@ module.exports = (function() {
} else {
dataType = attribute;
}
if (dataType === undefined) {
throw new Error('Unrecognized data type for field ' + name);
}
......@@ -401,7 +401,7 @@ module.exports = (function() {
return self.drop(options);
}
}).then(function () {
return self.QueryInterface.createTable(self.getTableName(), attributes, options);
return self.QueryInterface.createTable(self.getTableName(options), attributes, options);
}).return(this);
};
......@@ -412,7 +412,7 @@ module.exports = (function() {
* @return {Promise}
*/
Model.prototype.drop = function(options) {
return this.QueryInterface.dropTable(this.getTableName(), options);
return this.QueryInterface.dropTable(this.getTableName(options), options);
};
Model.prototype.dropSchema = function(schema) {
......@@ -450,7 +450,7 @@ module.exports = (function() {
*
* @return {String|Object}
*/
Model.prototype.getTableName = function() {
Model.prototype.getTableName = function(options) {
return this.QueryGenerator.addSchema(this);
};
......@@ -691,7 +691,7 @@ module.exports = (function() {
options = paranoidClause.call(this, options);
return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({
type: QueryTypes.SELECT,
hasJoin: hasJoin,
tableNames: Object.keys(tableNames)
......@@ -705,7 +705,7 @@ module.exports = (function() {
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || null;
return this.QueryInterface.select(this, [[this.getTableName(), this.name], joinTableName], optcpy, Utils._.defaults({
return this.QueryInterface.select(this, [[this.getTableName(options), this.name], joinTableName], optcpy, Utils._.defaults({
type: QueryTypes.SELECT
}, queryOptions, { transaction: (options || {}).transaction }));
};
......@@ -798,7 +798,7 @@ module.exports = (function() {
mapFieldNames.call(this, options, this);
options = paranoidClause.call(this, options);
return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({
plain: true,
type: QueryTypes.SELECT,
hasJoin: hasJoin,
......@@ -832,7 +832,7 @@ module.exports = (function() {
options = paranoidClause.call(this, options);
return this.QueryInterface.rawSelect(this.getTableName(), options, aggregateFunction, this);
return this.QueryInterface.rawSelect(this.getTableName(options), options, aggregateFunction, this);
};
/**
......@@ -1250,7 +1250,7 @@ module.exports = (function() {
}
// Insert all records at once
return self.QueryInterface.bulkInsert(self.getTableName(), records, options, attributes);
return self.QueryInterface.bulkInsert(self.getTableName(options), records, options, attributes);
}
}).then(function() {
// Run after hook
......@@ -1311,9 +1311,9 @@ module.exports = (function() {
if (self._timestampAttributes.deletedAt && !options.force) {
var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = Utils.now(self.modelManager.sequelize.options.dialect);
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, where, options, self.rawAttributes);
return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, where, options, self.rawAttributes);
} else {
return self.QueryInterface.bulkDelete(self.getTableName(), where, options, self);
return self.QueryInterface.bulkDelete(self.getTableName(options), where, options, self);
}
}).tap(function() {
// Run afterDestroy hook on each record individually
......@@ -1457,7 +1457,7 @@ module.exports = (function() {
}
// Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHashUse, where, options, self.tableAttributes).then(function(affectedRows) {
return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHashUse, where, options, self.tableAttributes).then(function(affectedRows) {
return [affectedRows];
});
}).tap(function(result) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!