diff --git a/core/server/models/member.js b/core/server/models/member.js index dcf96473a7..5991a3b770 100644 --- a/core/server/models/member.js +++ b/core/server/models/member.js @@ -1,7 +1,24 @@ const ghostBookshelf = require('./base'); const Member = ghostBookshelf.Model.extend({ - tableName: 'members' + tableName: 'members', + + emitChange: function emitChange(event, options) { + const eventToTrigger = 'member' + '.' + event; + ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options); + }, + + onCreated: function onCreated(model, attrs, options) { + ghostBookshelf.Model.prototype.onCreated.apply(this, arguments); + + model.emitChange('added', options); + }, + + onDestroyed: function onDestroyed(model, options) { + ghostBookshelf.Model.prototype.onDestroyed.apply(this, arguments); + + model.emitChange('deleted', options); + } }); const Members = ghostBookshelf.Collection.extend({