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
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
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
@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 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 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 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
@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
@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
@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
@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
@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
@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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.