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
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.
324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/dm-core/associations/many_to_many.rb', line 324 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 return false unless intermediaries.all(via => self).destroy 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 |
# 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) return false unless intermediaries.all(via => self).destroy! return false unless model.all(repository: repository, conditions: conditions).destroy! each do |resource| resource.persistence_state = Resource::PersistenceState::Immutable.new(resource) end clear true end |
#intermediaries ⇒ Collection
Return the intermediaries linking the source to the targets
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/dm-core/associations/many_to_many.rb', line 372 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
389 390 391 |
# File 'lib/dm-core/associations/many_to_many.rb', line 389 protected 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.
394 395 396 |
# File 'lib/dm-core/associations/many_to_many.rb', line 394 protected 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.
399 400 401 |
# File 'lib/dm-core/associations/many_to_many.rb', line 399 protected def via relationship.via end |