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

Commit 6a36800f by Thaddeus Quintin

Added option passing back to the getTableName function.

1 parent 7895f286
Showing with 15 additions and 15 deletions
...@@ -389,9 +389,9 @@ module.exports = (function() { ...@@ -389,9 +389,9 @@ 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);
}).then(function () { }).then(function () {
return self.QueryInterface.showIndex(self.getTableName(), options); return self.QueryInterface.showIndex(self.getTableName(options), options);
}).then(function (indexes) { }).then(function (indexes) {
// Assign an auto-generated name to indexes which are not named by the user // Assign an auto-generated name to indexes which are not named by the user
self.options.indexes = self.QueryInterface.nameIndexes(self.options.indexes, self.tableName); self.options.indexes = self.QueryInterface.nameIndexes(self.options.indexes, self.tableName);
...@@ -403,7 +403,7 @@ module.exports = (function() { ...@@ -403,7 +403,7 @@ module.exports = (function() {
}); });
return Promise.map(indexes, function (index) { return Promise.map(indexes, function (index) {
return self.QueryInterface.addIndex(self.getTableName(), index.fields, index, self.tableName); return self.QueryInterface.addIndex(self.getTableName(options), index.fields, index, self.tableName);
}); });
}).return(this); }).return(this);
}; };
...@@ -415,7 +415,7 @@ module.exports = (function() { ...@@ -415,7 +415,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) {
...@@ -454,7 +454,7 @@ module.exports = (function() { ...@@ -454,7 +454,7 @@ module.exports = (function() {
* @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2) * @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2)
* @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);
}; };
...@@ -676,7 +676,7 @@ module.exports = (function() { ...@@ -676,7 +676,7 @@ module.exports = (function() {
var hasJoin = false var hasJoin = false
, tableNames = { }; , tableNames = { };
tableNames[this.getTableName()] = true; tableNames[this.getTableName(options)] = true;
options = optClone(options || {}); options = optClone(options || {});
options = Utils._.defaults(options, { options = Utils._.defaults(options, {
...@@ -725,7 +725,7 @@ module.exports = (function() { ...@@ -725,7 +725,7 @@ module.exports = (function() {
return this.runHooks('beforeFindAfterOptions', options); return this.runHooks('beforeFindAfterOptions', options);
} }
}).then(function() { }).then(function() {
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)
...@@ -744,7 +744,7 @@ module.exports = (function() { ...@@ -744,7 +744,7 @@ module.exports = (function() {
// whereCollection is used for non-primary key updates // whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null; this.options.whereCollection = options.where || null;
return this.QueryInterface.select(this, [[this.getTableName(), this.name], joinTableName], options, Utils._.defaults({ return this.QueryInterface.select(this, [[this.getTableName(options), this.name], joinTableName], options, Utils._.defaults({
type: QueryTypes.SELECT type: QueryTypes.SELECT
}, queryOptions, { transaction: (options || {}).transaction })); }, queryOptions, { transaction: (options || {}).transaction }));
}; };
...@@ -817,7 +817,7 @@ module.exports = (function() { ...@@ -817,7 +817,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);
}; };
/** /**
...@@ -1214,7 +1214,7 @@ module.exports = (function() { ...@@ -1214,7 +1214,7 @@ module.exports = (function() {
delete values[this.primaryKeyField]; delete values[this.primaryKeyField];
} }
return this.QueryInterface.upsert(this.getTableName(), values, this, options); return this.QueryInterface.upsert(this.getTableName(options), values, this, options);
}; };
Model.prototype.insertOrUpdate = Model.prototype.upsert; Model.prototype.insertOrUpdate = Model.prototype.upsert;
...@@ -1376,7 +1376,7 @@ module.exports = (function() { ...@@ -1376,7 +1376,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
...@@ -1438,9 +1438,9 @@ module.exports = (function() { ...@@ -1438,9 +1438,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, options.where, options, self.rawAttributes); return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, options.where, options, self.rawAttributes);
} else { } else {
return self.QueryInterface.bulkDelete(self.getTableName(), options.where, options, self); return self.QueryInterface.bulkDelete(self.getTableName(options), options.where, options, self);
} }
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
...@@ -1507,7 +1507,7 @@ module.exports = (function() { ...@@ -1507,7 +1507,7 @@ module.exports = (function() {
var attrValueHash = {}; var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = null; attrValueHash[self._timestampAttributes.deletedAt] = null;
options.omitNull = false; options.omitNull = false;
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, options.where, options, self._timestampAttributes.deletedAt); return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, options.where, options, self._timestampAttributes.deletedAt);
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
...@@ -1671,7 +1671,7 @@ module.exports = (function() { ...@@ -1671,7 +1671,7 @@ module.exports = (function() {
mapFieldNames.call(self, options, self); mapFieldNames.call(self, options, self);
// Run query to update all rows // Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) { return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) {
if (options.returning) { if (options.returning) {
daos = affectedRows; daos = affectedRows;
return [affectedRows.length, affectedRows]; return [affectedRows.length, affectedRows];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!