Class/Module Index [+]

Quicksearch

DataMapper::Associations::ManyToMany::Collection

Public Instance Methods

destroy() click to toggle source

Remove every Resource in the m:m Collection from the repository

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

@return [Boolean]

true if the resources were successfully destroyed

@api public

# File lib/dm-core/associations/many_to_many.rb, line 328
def destroy
  assert_source_saved 'The source must be saved before mass-deleting the collection'

  # make sure the records are loaded so they can be found when
  # the intermediaries are removed
  lazy_load

  unless intermediaries.all(via => self).destroy
    return false
  end

  super
end
destroy!() click to toggle source

Remove every Resource in the m:m Collection 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.

@return [Boolean]

true if the resources were successfully destroyed

@api public

# File lib/dm-core/associations/many_to_many.rb, line 352
def destroy!
  assert_source_saved 'The source must be saved before mass-deleting the collection'

  model      = self.model
  key        = model.key(repository_name)
  conditions = Query.target_conditions(self, key, key)

  unless intermediaries.all(via => self).destroy!
    return false
  end

  unless model.all(:repository => repository, :conditions => conditions).destroy!
    return false
  end

  each do |resource|
    resource.persistence_state = Resource::PersistenceState::Immutable.new(resource)
  end

  clear

  true
end
intermediaries() click to toggle source

Return the intermediaries linking the source to the targets

@return [Collection]

the intermediary collection

@api public

# File lib/dm-core/associations/many_to_many.rb, line 382
def intermediaries
  through = self.through
  source  = self.source

  @intermediaries ||= if through.loaded?(source)
    through.get_collection(source)
  else
    reset_intermediaries
  end
end

Protected Instance Methods

intermediary_for() click to toggle source

Map the resources in the collection to the intermediaries

@return [Hash]

the map of resources to their intermediaries

@api private

# File lib/dm-core/associations/many_to_many.rb, line 401
def intermediary_for
  @intermediary_for ||= {}
end
through() click to toggle source

@api private

# File lib/dm-core/associations/many_to_many.rb, line 406
def through
  relationship.through
end
via() click to toggle source

@api private

# File lib/dm-core/associations/many_to_many.rb, line 411
def via
  relationship.via
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.