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

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