class BufferCategory include Mongoid::Document include Mongoid::Timestamps belongs_to :category belongs_to :categorizable, polymorphic: true before_destroy :remove_categorizable_category_id private def remove_categorizable_category_id self.categorizable.remove_id(self.category.id) end end