mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Added initial Comment model
refs https://github.com/TryGhost/Team/issues/1664
This commit is contained in:
parent
ed7ce2c00f
commit
a5874f90fe
43
core/server/models/comment.js
Normal file
43
core/server/models/comment.js
Normal 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)
|
||||
};
|
Loading…
Reference in New Issue
Block a user