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

Commit a4288ad7 by Jan Aagaard Meier

Default query type to select when callee is set. Closes #3415

1 parent 6ef3ed62
...@@ -8,6 +8,7 @@ var Utils = require('./utils') ...@@ -8,6 +8,7 @@ var Utils = require('./utils')
, BelongsToMany = require('./associations/belongs-to-many') , BelongsToMany = require('./associations/belongs-to-many')
, InstanceValidator = require('./instance-validator') , InstanceValidator = require('./instance-validator')
, DataTypes = require('./data-types') , DataTypes = require('./data-types')
, QueryTypes = require('./query-types')
, Promise = require("./promise") , Promise = require("./promise")
, _ = require('lodash') , _ = require('lodash')
, defaultsOptions = { raw: true } , defaultsOptions = { raw: true }
...@@ -808,7 +809,7 @@ module.exports = (function() { ...@@ -808,7 +809,7 @@ module.exports = (function() {
} else { } else {
where = {}; where = {};
where[self.Model.rawAttributes[self.Model.primaryKeyAttribute].field] = self.get(self.Model.primaryKeyAttribute, {raw: true}); where[self.Model.rawAttributes[self.Model.primaryKeyAttribute].field] = self.get(self.Model.primaryKeyAttribute, {raw: true});
return self.QueryInterface.delete(self, self.Model.getTableName(options), where, _.defaults(options, {limit: null})); return self.QueryInterface.delete(self, self.Model.getTableName(options), where, _.defaults(options, { type: QueryTypes.DELETE,limit: null}));
} }
}).tap(function(result) { }).tap(function(result) {
// Run after hook // Run after hook
......
...@@ -1533,7 +1533,7 @@ module.exports = (function() { ...@@ -1533,7 +1533,7 @@ module.exports = (function() {
individualHooks: false individualHooks: false
}, options || {}); }, options || {});
options.type = QueryTypes.BULKUNDELETE; options.type = QueryTypes.RAW;
var self = this var self = this
, instances; , instances;
......
...@@ -686,6 +686,8 @@ module.exports = (function() { ...@@ -686,6 +686,8 @@ module.exports = (function() {
QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) { QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) {
var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes); var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes);
options.type = QueryTypes.RAW;
return this.sequelize.query(sql, dao, options); return this.sequelize.query(sql, dao, options);
}; };
......
...@@ -6,6 +6,7 @@ module.exports = { ...@@ -6,6 +6,7 @@ module.exports = {
UPDATE: 'UPDATE', UPDATE: 'UPDATE',
BULKUPDATE: 'BULKUPDATE', BULKUPDATE: 'BULKUPDATE',
BULKDELETE: 'BULKDELETE', BULKDELETE: 'BULKDELETE',
DELETE: 'DELETE',
UPSERT: 'UPSERT', UPSERT: 'UPSERT',
VERSION: 'VERSION', VERSION: 'VERSION',
SHOWTABLES: 'SHOWTABLES', SHOWTABLES: 'SHOWTABLES',
......
...@@ -653,7 +653,7 @@ module.exports = (function() { ...@@ -653,7 +653,7 @@ module.exports = (function() {
* *
* @method query * @method query
* @param {String} sql * @param {String} sql
* @param {Instance|Model} [callee] If callee is provided, the returned data will be put into the callee * @param {Instance|Model} [callee] If callee is provided, the returned data will be put into the callee, and `type` will default to SELECT
* @param {Object} [options={}] Query options. * @param {Object} [options={}] Query options.
* @param {Boolean} [options.raw] If true, sequelize will not try to format the results of the query, or build an instance of a model from the result * @param {Boolean} [options.raw] If true, sequelize will not try to format the results of the query, or build an instance of a model from the result
* @param {Transaction} [options.transaction=null] The transaction that the query should be executed under * @param {Transaction} [options.transaction=null] The transaction that the query should be executed under
...@@ -725,7 +725,7 @@ module.exports = (function() { ...@@ -725,7 +725,7 @@ module.exports = (function() {
} }
if (!options.type) { if (!options.type) {
if (options.nest || options.plain) { if (callee || options.nest || options.plain) {
options.type = QueryTypes.SELECT; options.type = QueryTypes.SELECT;
} else { } else {
options.type = QueryTypes.RAW; options.type = QueryTypes.RAW;
......
...@@ -284,7 +284,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() { ...@@ -284,7 +284,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
it('uses the passed model', function() { it('uses the passed model', function() {
return this.sequelize.query(this.insertQuery).bind(this).then(function() { return this.sequelize.query(this.insertQuery).bind(this).then(function() {
return this.sequelize.query('SELECT * FROM ' + qq(this.User.tableName) + ';', this.User, { type: this.sequelize.QueryTypes.SELECT }); return this.sequelize.query('SELECT * FROM ' + qq(this.User.tableName) + ';', this.User);
}).then(function(users) { }).then(function(users) {
expect(users[0].Model).to.equal(this.User); expect(users[0].Model).to.equal(this.User);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!