mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +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
30 lines
764 B
JavaScript
30 lines
764 B
JavaScript
'use strict';
|
|
|
|
const ghostBookshelf = require('./base'),
|
|
Basetoken = require('./base/token');
|
|
|
|
let Accesstoken,
|
|
Accesstokens;
|
|
|
|
Accesstoken = Basetoken.extend({
|
|
tableName: 'accesstokens',
|
|
|
|
emitChange: function emitChange(event, options) {
|
|
const eventToTrigger = 'token' + '.' + event;
|
|
ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options);
|
|
},
|
|
|
|
onCreated: function onCreated(model, attrs, options) {
|
|
model.emitChange('added', options);
|
|
}
|
|
});
|
|
|
|
Accesstokens = ghostBookshelf.Collection.extend({
|
|
model: Accesstoken
|
|
});
|
|
|
|
module.exports = {
|
|
Accesstoken: ghostBookshelf.model('Accesstoken', Accesstoken),
|
|
Accesstokens: ghostBookshelf.collection('Accesstokens', Accesstokens)
|
|
};
|