Method: DataMapper::Collection#destroy!

Defined in:
lib/dm-core/collection.rb

#destroy!Boolean

Remove all Resources from the repository, bypassing validation

This performs a deletion of each Resource in the Collection from the repository and clears the Collection while skipping validation.

Returns:

  • (Boolean)

    true if the resources were successfully destroyed



912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
# File 'lib/dm-core/collection.rb', line 912

def destroy!
  repository = self.repository
  deleted    = repository.delete(self)

  if loaded?
    unless deleted == size
      return false
    end

    each do |resource|
      resource.persisted_state = Resource::State::Immutable.new(resource)
    end

    clear
  else
    mark_loaded
  end

  true
end