Class: DataMapper::Associations::ManyToMany::Collection
- Inherits:
-
OneToMany::Collection
- Object
- LazyArray
- Collection
- OneToMany::Collection
- DataMapper::Associations::ManyToMany::Collection
- Defined in:
- lib/dm-core/associations/many_to_many.rb
Overview
class Relationship
Instance Attribute Summary
Attributes inherited from OneToMany::Collection
Attributes inherited from Collection
Attributes inherited from LazyArray
Instance Method Summary collapse
-
#destroy ⇒ Boolean
Remove every Resource in the m:m Collection from the repository.
-
#destroy! ⇒ Boolean
Remove every Resource in the m:m Collection from the repository, bypassing validation.
-
#intermediaries ⇒ Collection
Return the intermediaries linking the source to the targets.
-
#intermediary_for ⇒ Hash
protected
private
Map the resources in the collection to the intermediaries.
- #through ⇒ Object protected private
- #via ⇒ Object protected private
Methods inherited from OneToMany::Collection
#clear, #reload, #replace, #update, #update!
Methods inherited from Collection
#<<, #[], #[]=, #all, #at, #clean?, #clear, #collect!, #concat, #create, #create!, #delete, #delete_at, #delete_if, #difference, #dirty?, #each, #first, #first_or_create, #first_or_new, #get, #get!, #hash, #insert, #inspect, #intersection, #last, #loaded_entries, #model, #model_key, #new, #pop, #properties, #push, #reject!, #relationships, #reload, #replace, #repository, #respond_to?, #reverse, #reverse!, #save, #save!, #set, #shift, #slice!, #union, #unshift, #update, #update!
Methods inherited from LazyArray
#<<, #==, #[], #[]=, #any?, #at, #clear, #concat, #delete_at, #delete_if, #empty?, #eql?, #fetch, #first, #freeze, #frozen?, #include?, #index, #insert, #kind_of?, #last, #lazy_possible?, #load_with, #loaded?, #pop, #push, #replace, #respond_to?, #reverse, #reverse!, #shift, #slice!, #to_a, #unshift, #values_at
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DataMapper::Collection
Instance Method Details
#destroy ⇒ Boolean
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.
322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/dm-core/associations/many_to_many.rb', line 322 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! ⇒ Boolean
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.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/dm-core/associations/many_to_many.rb', line 346 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.persisted_state = Resource::State::Immutable.new(resource) end clear true end |
#intermediaries ⇒ Collection
Return the intermediaries linking the source to the targets
376 377 378 379 380 381 382 383 384 385 |
# File 'lib/dm-core/associations/many_to_many.rb', line 376 def intermediaries through = self.through source = self.source @intermediaries ||= if through.loaded?(source) through.get_collection(source) else reset_intermediaries end end |
#intermediary_for ⇒ Hash (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Map the resources in the collection to the intermediaries
395 396 397 |
# File 'lib/dm-core/associations/many_to_many.rb', line 395 def intermediary_for @intermediary_for ||= {} end |
#through ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
400 401 402 |
# File 'lib/dm-core/associations/many_to_many.rb', line 400 def through relationship.through end |
#via ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
405 406 407 |
# File 'lib/dm-core/associations/many_to_many.rb', line 405 def via relationship.via end |