mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Custom destroy method for posts
issue #858 - correctly handles detaching tags before deleting the post
This commit is contained in:
parent
e6b779330f
commit
d544b4aebb
1 changed files with 13 additions and 0 deletions
|
@ -332,6 +332,19 @@ Post = GhostBookshelf.Model.extend({
|
|||
// associated models can't be created until the post has an ID, so run this after
|
||||
return post.updateTags(newPostData.tags);
|
||||
});
|
||||
},
|
||||
destroy: function (_identifier, options) {
|
||||
options = options || {};
|
||||
return this.forge({id: _identifier}).fetch({withRelated: ['tags']}).then(function destroyTags(post) {
|
||||
var tagIds = _.pluck(post.related('tags').toJSON(), 'id');
|
||||
if (tagIds) {
|
||||
return post.tags().detach(tagIds).then(function destroyPost() {
|
||||
return post.destroy(options);
|
||||
});
|
||||
}
|
||||
|
||||
return post.destroy(options);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue