function on_delete($post_master) { // if tag is not related to any other group, delete it $list = new TagsToTagsGroups_list(); //check if tag is related to any other group, if not remove it if (!$list->search(array('search_tag_id' => $this->tag_id, 'search_not_id' => $this->id))) { //delete directly to avoid calling on_delete actions recursively $post_master->sql_delete_list('articles_tags', "tag_id={$this->tag_id}"); $post_master->sql_delete_list('tags', "id={$this->tag_id}"); } }