0
Fork 0
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:
Hannah Wolfe 2013-09-27 11:56:20 +01:00
parent e6b779330f
commit d544b4aebb

View file

@ -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);
});
}
});