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

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')
, BelongsToMany = require('./associations/belongs-to-many')
, InstanceValidator = require('./instance-validator')
, DataTypes = require('./data-types')
, QueryTypes = require('./query-types')
, Promise = require("./promise")
, _ = require('lodash')
, defaultsOptions = { raw: true }
......@@ -808,7 +809,7 @@ module.exports = (function() {
} else {
where = {};
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) {
// Run after hook
......
......@@ -1533,7 +1533,7 @@ module.exports = (function() {
individualHooks: false
}, options || {});
options.type = QueryTypes.BULKUNDELETE;
options.type = QueryTypes.RAW;
var self = this
, instances;
......
......@@ -686,6 +686,8 @@ module.exports = (function() {
QueryInterface.prototype.increment = function(dao, tableName, values, identifier, options) {
var sql = this.QueryGenerator.incrementQuery(tableName, values, identifier, options.attributes);
options.type = QueryTypes.RAW;
return this.sequelize.query(sql, dao, options);
};
......
......@@ -6,6 +6,7 @@ module.exports = {
UPDATE: 'UPDATE',
BULKUPDATE: 'BULKUPDATE',
BULKDELETE: 'BULKDELETE',
DELETE: 'DELETE',
UPSERT: 'UPSERT',
VERSION: 'VERSION',
SHOWTABLES: 'SHOWTABLES',
......
......@@ -653,7 +653,7 @@ module.exports = (function() {
*
* @method query
* @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 {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
......@@ -725,7 +725,7 @@ module.exports = (function() {
}
if (!options.type) {
if (options.nest || options.plain) {
if (callee || options.nest || options.plain) {
options.type = QueryTypes.SELECT;
} else {
options.type = QueryTypes.RAW;
......
......@@ -284,7 +284,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
it('uses the passed model', 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) {
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!