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

Commit c63ccaf6 by Mick Hansen

Merge pull request #2419 from sheltond/master

sequelize/sequelize#2418 Don't overwrite autocommit setting for an outer transaction when using findOrCreate - closes #2418
2 parents 3a74da81 84824fab
......@@ -1130,10 +1130,15 @@ module.exports = (function() {
/**
* Returns a query that starts a transaction.
*
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query.
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
setAutocommitQuery: function(value) {
setAutocommitQuery: function(value, options) {
if (options.parent) {
return;
}
return 'SET autocommit = ' + (!!value ? 1 : 0) + ';';
},
......
......@@ -712,13 +712,21 @@ module.exports = (function() {
return this.QueryGenerator.escape(value);
};
QueryInterface.prototype.setAutocommit = function(transaction, value) {
QueryInterface.prototype.setAutocommit = function(transaction, value, options) {
if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set autocommit for a transaction without transaction object!');
}
var sql = this.QueryGenerator.setAutocommitQuery(value);
return this.sequelize.query(sql, null, { transaction: transaction});
options = Utils._.extend({
parent: options.transaction
}, options || {});
var sql = this.QueryGenerator.setAutocommitQuery(value, options);
if (sql) {
return this.sequelize.query(sql, null, { transaction: transaction });
} else {
return Utils.Promise.resolve();
}
};
QueryInterface.prototype.setIsolationLevel = function(transaction, value, options) {
......
......@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
return this
.sequelize
.getQueryInterface()
.setAutocommit(this, this.options.autocommit);
.setAutocommit(this, this.options.autocommit, this.options);
};
Transaction.prototype.setIsolationLevel = function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!