app/models/data_object.rb
# Because dependent destroy was too scary for us.  :|
Because dependent destroy was too scary for us.
Because dependent destroy was too scary for us .
def destroy_everything
    Rails.logger.error("** Destroying DataObject #{id}")
    agents_data_objects.destroy_all 
    data_objects_hierarchy_entries.destroy_all 
    data_objects_taxon_concepts.destroy_all 
    curated_data_objects_hierarchy_entries.destroy_all 
    comments.destroy_all
    data_objects_table_of_contents.destroy_all
    data_objects_info_items.destroy_all
    taxon_concept_exemplar_images.destroy_all
    worklist_ignored_data_objects.destroy_all
    collection_items.destroy_all
    curator_activity_logs.destroy_all
    users_data_objects_ratings.destroy_all
    refs_ids = []
    DataObjectsRef.where(data_object_id: id).each do |data_object_ref|
      refs_ids << data_object_ref.ref_id
      data_object_ref.destroy
    end
    Ref.where(id: refs_ids).each { |ref| ref.destroy if ref.data_objects.count == 0 }
    DataObjectsHierarchyEntry.where(data_object_id: id).destroy_all
    AgentsDataObject.where(data_object_id: id).destroy_all
    DataObjectsTaxonConcept.where(data_object_id: id).destroy_all
    DataObjectsTableOfContent.where(data_object_id: id).destroy_all
    Rails.logger.error("** Destroyed DataObject #{id}")
  end
def destroy_everything Rails . logger . error ( "** Destroying DataObject #{id}" ) agents_data_objects . destroy_all data_objects_hierarchy_entries . destroy_all data_objects_taxon_concepts . destroy_all curated_data_objects_hierarchy_entries . destroy_all comments . destroy_all data_objects_table_of_contents . destroy_all data_objects_info_items . destroy_all taxon_concept_exemplar_images . destroy_all worklist_ignored_data_objects . destroy_all collection_items . destroy_all curator_activity_logs . destroy_all users_data_objects_ratings . destroy_all refs_ids = [ ] DataObjectsRef . where ( data_object_id : id ) . each do | data_object_ref | refs_ids << data_object_ref . ref_id data_object_ref . destroy end Ref . where ( id : refs_ids ) . each { | ref | ref . destroy if ref . data_objects . count == 0 } DataObjectsHierarchyEntry . where ( data_object_id : id ) . destroy_all AgentsDataObject . where ( data_object_id : id ) . destroy_all DataObjectsTaxonConcept . where ( data_object_id : id ) . destroy_all DataObjectsTableOfContent . where ( data_object_id : id ) . destroy_all Rails . logger . error ( "** Destroyed DataObject #{id}" ) end
Because dependent destroy was too scary for us.
Because dependent destroy was too scary for us .
# Too slow, probably not needed anyway: dato.top_images.destroy_all # Same with top_concept_images #TODO: These should probably be handled with dependent destroys. # denorm table # denorm # denorm # denorm # TODO: handle translations # refs.destroy_all # through the join table, here: # DataObjectsRef.where(data_object_id: id).destroy_all #ref_ids = refs.map(:id)