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

Commit 84824fab by Daniel Shelton

sequelize/sequelize#2418 Don't overwrite autocommit setting for an outer transac…

…tion when using findOrCreate
1 parent 3a74da81
...@@ -1131,9 +1131,14 @@ module.exports = (function() { ...@@ -1131,9 +1131,14 @@ module.exports = (function() {
* Returns a query that starts a transaction. * Returns a query that starts a transaction.
* *
* @param {Boolean} value A boolean that states whether autocommit shall be done or not. * @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. * @return {String} The generated sql query.
*/ */
setAutocommitQuery: function(value) { setAutocommitQuery: function(value, options) {
if (options.parent) {
return;
}
return 'SET autocommit = ' + (!!value ? 1 : 0) + ';'; return 'SET autocommit = ' + (!!value ? 1 : 0) + ';';
}, },
......
...@@ -712,13 +712,21 @@ module.exports = (function() { ...@@ -712,13 +712,21 @@ module.exports = (function() {
return this.QueryGenerator.escape(value); return this.QueryGenerator.escape(value);
}; };
QueryInterface.prototype.setAutocommit = function(transaction, value) { QueryInterface.prototype.setAutocommit = function(transaction, value, options) {
if (!transaction || !(transaction instanceof Transaction)) { if (!transaction || !(transaction instanceof Transaction)) {
throw new Error('Unable to set autocommit for a transaction without transaction object!'); throw new Error('Unable to set autocommit for a transaction without transaction object!');
} }
var sql = this.QueryGenerator.setAutocommitQuery(value); options = Utils._.extend({
return this.sequelize.query(sql, null, { transaction: transaction}); 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) { QueryInterface.prototype.setIsolationLevel = function(transaction, value, options) {
......
...@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() { ...@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
return this return this
.sequelize .sequelize
.getQueryInterface() .getQueryInterface()
.setAutocommit(this, this.options.autocommit); .setAutocommit(this, this.options.autocommit, this.options);
}; };
Transaction.prototype.setIsolationLevel = function() { 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!