Added initial Comment model

refs https://github.com/TryGhost/Team/issues/1664
This commit is contained in:
Kevin Ansfield 2022-07-05 11:34:10 +02:00 committed by Simon Backx
parent ed7ce2c00f
commit a5874f90fe

View File

@ -0,0 +1,43 @@
const ghostBookshelf = require('./base');
const Comment = ghostBookshelf.Model.extend({
tableName: 'comments',
defaults: function defaults() {
return {
status: 'published'
};
},
post() {
return this.belongsTo('Post', 'post_id');
},
member() {
return this.belongsTo('Member', 'member_id');
},
parent() {
return this.belongsTo('Comment', 'parent_id');
},
emitChange: function emitChange(event, options) {
const eventToTrigger = 'comment' + '.' + event;
ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options);
},
onCreated: function onCreated(model, options) {
ghostBookshelf.Model.prototype.onCreated.apply(this, arguments);
model.emitChange('added', options);
}
});
const Comments = ghostBookshelf.Collection.extend({
model: Comment
});
module.exports = {
Comment: ghostBookshelf.model('Comment', Comment),
Comments: ghostBookshelf.collection('Comments', Comments)
};