mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 22:13:20 +03:00
fb79f24316
no issue - if multiple queries run in a transaction, the model events are triggered before the txn finished - if the txn rolls back, the events are anyway emitted - the events are triggered too early - solution: - `emitChange` needs to detect that a transaction is happening - it listens on a txn event to determine if events should be triggered
29 lines
714 B
JavaScript
29 lines
714 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* This is a feature request in knex for 1.0.
|
|
* https://github.com/tgriesser/knex/issues/1641
|
|
*/
|
|
module.exports = function (bookshelf) {
|
|
const orig1 = bookshelf.transaction;
|
|
|
|
bookshelf.transaction = function (cb) {
|
|
return orig1.bind(bookshelf)(function (t) {
|
|
const orig2 = t.commit;
|
|
const orig3 = t.rollback;
|
|
|
|
t.commit = function () {
|
|
t.emit('committed', true);
|
|
return orig2.apply(t, arguments);
|
|
};
|
|
|
|
t.rollback = function () {
|
|
t.emit('committed', false);
|
|
return orig3.apply(t, arguments);
|
|
};
|
|
|
|
return cb(t);
|
|
});
|
|
};
|
|
};
|