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
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 between the source and the targets.
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, #dirty?, #first, #first_or_create, #first_or_new, #get, #get!, #insert, #inspect, #last, #model, #new, #pop, #properties, #push, #reject!, #relationships, #reload, #replace, #repository, #respond_to?, #reverse, #reverse!, #save, #save!, #shift, #slice!, #unshift, #update, #update!
Methods included from Deprecate
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.
308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/dm-core/associations/many_to_many.rb', line 308 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.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.
332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/dm-core/associations/many_to_many.rb', line 332 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.destroy! return false end super end |
#intermediaries ⇒ Collection
Return the intermediaries between the source and the targets
352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/dm-core/associations/many_to_many.rb', line 352 def intermediaries return @intermediaries if @intermediaries intermediaries = if through.loaded?(source) through.get!(source) else through.set!(source, through.collection_for(source)) end scoped = intermediaries.all(via => self) @intermediaries = scoped.query == intermediaries.query ? intermediaries : scoped end |