class Tagging include Mongoid::Document include Mongoid::Timestamps field :to_destroy, default: false belongs_to :tag belongs_to :taggable, polymorphic: true before_destroy :update_taggable_tag_ids private def update_taggable_tag_ids self.taggable.remove_id(self.tag.id) end end