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

Commit 11347233 by Mick Hansen

Merge pull request #1952 from quiddle/pass-options-to-getTableName

Pass options to getTableName function
2 parents 938e167f 40c474b5
Showing with 13 additions and 12 deletions
......@@ -402,7 +402,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);
};
......@@ -413,7 +413,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) {
......@@ -449,9 +449,10 @@ module.exports = (function() {
* Get the tablename of the model, taking schema into account. The method will return The name as a string if the model has no schema,
* or an object with `tableName`, `schema` and `delimiter` properties.
*
* @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}
*/
Model.prototype.getTableName = function() {
Model.prototype.getTableName = function(options) {
return this.QueryGenerator.addSchema(this);
};
......@@ -643,7 +644,7 @@ module.exports = (function() {
* @param {Object} [options.where] A hash of attributes to describe your search. See above for examples.
* @param {Array<String>} [options.attributes] A list of the attributes that you want to select. To rename an attribute, you can pass an array, with two elements - the first is the name of the attribute in the DB (or some kind of expression such as `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to have in the returned instance
* @param {Array<Object|Model>} [options.include] A list of associations to eagerly load using a left join. Supported is either `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`. If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in the as attribute when eager loading Y).
* @param {Model} [optinos.include[].model] The model you want to eagerly load
* @param {Model} [options.include[].model] The model you want to eagerly load
* @param {String} [options.include[].as] The alias of the relation, in case the model you want to eagerly load is aliassed.
* @param {Object} [options.include[].where] Where clauses to apply to the child models. Note that this converts the eager load to an inner join, unless you explicitly set `required: true`
* @param {Array<String>} [options.include[].attributes] A list of attributes to select from the child model
......@@ -692,7 +693,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)
......@@ -706,7 +707,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 }));
};
......@@ -799,7 +800,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,
......@@ -833,7 +834,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);
};
/**
......@@ -1251,7 +1252,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
......@@ -1312,9 +1313,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
......@@ -1460,7 +1461,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) {
if (options.returning) {
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!