Class: DataMapper::Associations::OneToMany::Collection

Inherits:
Collection show all
Defined in:
lib/dm-core/associations/one_to_many.rb

Overview

class Relationship

Direct Known Subclasses

ManyToMany::Collection

Instance Attribute Summary collapse

Attributes inherited from Collection

#query

Attributes inherited from LazyArray

#head, #tail

Instance Method Summary collapse

Methods inherited from Collection

#<<, #[], #[]=, #all, #at, #clean?, #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, #repository, #respond_to?, #reverse, #reverse!, #save, #save!, #set, #shift, #slice!, #union, #unshift

Methods inherited from LazyArray

#<<, #==, #[], #[]=, #any?, #at, #concat, #delete_at, #delete_if, #empty?, #eql?, #fetch, #first, #freeze, #frozen?, #include?, #index, #insert, #kind_of?, #last, #lazy_possible?, #load_with, #loaded?, #pop, #push, #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 Attribute Details

#relationshipObject

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.


184
185
186
# File 'lib/dm-core/associations/one_to_many.rb', line 184

def relationship
  @relationship
end

#sourceObject

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.


187
188
189
# File 'lib/dm-core/associations/one_to_many.rb', line 187

def source
  @source
end

Instance Method Details

#clearCollection

Removes all Resources from the 1:m Collection

This should remove and orphan each Resource from the 1:m Collection.

Returns:


217
218
219
220
# File 'lib/dm-core/associations/one_to_many.rb', line 217

def clear
  lazy_load  # lazy load so that targets are always orphaned
  super
end

#destroyBoolean

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

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

Returns:

  • (Boolean)

    true if the resources were successfully destroyed


259
260
261
262
# File 'lib/dm-core/associations/one_to_many.rb', line 259

def destroy
  assert_source_saved 'The source must be saved before mass-deleting the collection'
  super
end

#destroy!Boolean

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

Returns:

  • (Boolean)

    true if the resources were successfully destroyed


274
275
276
277
# File 'lib/dm-core/associations/one_to_many.rb', line 274

def destroy!
  assert_source_saved 'The source must be saved before mass-deleting the collection'
  super
end

#reloadObject


190
191
192
193
# File 'lib/dm-core/associations/one_to_many.rb', line 190

def reload(*)
  assert_source_saved 'The source must be saved before reloading the collection'
  super
end

#replaceCollection

Replace the Resources within the 1:m Collection

Parameters:

  • other (Enumerable)

    List of other Resources to replace with

Returns:


204
205
206
207
# File 'lib/dm-core/associations/one_to_many.rb', line 204

def replace(*)
  lazy_load  # lazy load so that targets are always orphaned
  super
end

#updateBoolean

Update every Resource in the 1:m Collection

Parameters:

  • attributes (Hash)

    attributes to update with

Returns:

  • (Boolean)

    true if the resources were successfully updated


231
232
233
234
# File 'lib/dm-core/associations/one_to_many.rb', line 231

def update(*)
  assert_source_saved 'The source must be saved before mass-updating the collection'
  super
end

#update!Boolean

Update every Resource in the 1:m Collection, bypassing validation

Parameters:

  • attributes (Hash)

    attributes to update

Returns:

  • (Boolean)

    true if the resources were successfully updated


245
246
247
248
# File 'lib/dm-core/associations/one_to_many.rb', line 245

def update!(*)
  assert_source_saved 'The source must be saved before mass-updating the collection'
  super
end