Class Index [+]

Quicksearch

DataMapper::Associations::OneToMany::Collection

Attributes

relationship[RW]

@api private

source[RW]

@api private

Public Instance Methods

clear() click to toggle source

Removes all Resources from the 1:m Collection

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

@return [Collection]

  self

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 214
214:         def clear
215:           lazy_load  # lazy load so that targets are always orphaned
216:           super
217:         end
destroy() click to toggle source

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.

@return [Boolean]

  true if the resources were successfully destroyed

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 256
256:         def destroy
257:           assert_source_saved 'The source must be saved before mass-deleting the collection'
258:           super
259:         end
destroy!() click to toggle source

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.

@return [Boolean]

  true if the resources were successfully destroyed

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 271
271:         def destroy!
272:           assert_source_saved 'The source must be saved before mass-deleting the collection'
273:           super
274:         end
reload(*) click to toggle source

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 187
187:         def reload(*)
188:           assert_source_saved 'The source must be saved before reloading the collection'
189:           super
190:         end
replace(*) click to toggle source

Replace the Resources within the 1:m Collection

@param [Enumerable] other

  List of other Resources to replace with

@return [Collection]

  self

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 201
201:         def replace(*)
202:           lazy_load  # lazy load so that targets are always orphaned
203:           super
204:         end
update(*) click to toggle source

Update every Resource in the 1:m Collection

@param [Hash] attributes

  attributes to update with

@return [Boolean]

  true if the resources were successfully updated

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 228
228:         def update(*)
229:           assert_source_saved 'The source must be saved before mass-updating the collection'
230:           super
231:         end
update!(*) click to toggle source

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

@param [Hash] attributes

  attributes to update

@return [Boolean]

  true if the resources were successfully updated

@api public

     # File lib/dm-core/associations/one_to_many.rb, line 242
242:         def update!(*)
243:           assert_source_saved 'The source must be saved before mass-updating the collection'
244:           super
245:         end

Private Instance Methods

_create(*) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 279
279:         def _create(*)
280:           assert_source_saved 'The source must be saved before creating a resource'
281:           super
282:         end
_save(execute_hooks = true) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 285
285:         def _save(execute_hooks = true)
286:           assert_source_saved 'The source must be saved before saving the collection'
287: 
288:           # update removed resources to not reference the source
289:           @removed.all? { |resource| resource.destroyed? || resource.__send__(execute_hooks ? :save : :save!) } && super
290:         end
assert_source_saved(message) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 337
337:         def assert_source_saved(message)
338:           unless source.saved?
339:             raise UnsavedParentError, message
340:           end
341:         end
inverse_set(source, target) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 330
330:         def inverse_set(source, target)
331:           unless source.readonly?
332:             relationship.inverse.set(source, target)
333:           end
334:         end
lazy_load() click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 293
293:         def lazy_load
294:           if source.saved?
295:             super
296:           end
297:         end
new_collection(query, resources = nil, &block) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 300
300:         def new_collection(query, resources = nil, &block)
301:           collection = self.class.new(query, &block)
302: 
303:           collection.relationship = relationship
304:           collection.source       = source
305: 
306:           resources ||= filter(query) if loaded?
307: 
308:           # set the resources after the relationship and source are set
309:           if resources
310:             collection.set(resources)
311:           end
312: 
313:           collection
314:         end
resource_added(resource) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 317
317:         def resource_added(resource)
318:           resource = initialize_resource(resource)
319:           inverse_set(resource, source)
320:           super
321:         end
resource_removed(resource) click to toggle source

@api private

     # File lib/dm-core/associations/one_to_many.rb, line 324
324:         def resource_removed(resource)
325:           inverse_set(resource, nil)
326:           super
327:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.