Sha256: 898c5121605d0aaccfb722f5ded8b115b017e15708e95ae42d2f0782764ad6c5
Contents?: true
Size: 1.37 KB
Versions: 57
Compression:
Stored size: 1.37 KB
Contents
# encoding: utf-8 module Mongoid # :nodoc: module Relations #:nodoc: module Cascading #:nodoc: class Delete attr_accessor :document, :relation, :metadata # Initialize the new cascade strategy, which will set up the relation # and the metadata. # # @example Instantiate the strategy # Strategy.new(document, metadata) # # @param [ Document ] document The document to cascade from. # @param [ Metadata ] metadata The relation's metadata. # # @return [ Strategy ] The new strategy. def initialize(document, metadata) @document, @metadata = document, metadata @relation = document.send(metadata.name) end # Execute the cascading deletion for the relation if it already exists. # This should be optimized in the future potentially not to load all # objects from the db. # # @example Perform the cascading delete. # strategy.cascade # # @since 2.0.0 def cascade if relation if relation.cascades.empty? safety = Threaded.safety_options relation.clear Threaded.safety_options = safety else ::Array.wrap(relation).each { |doc| doc.delete } end end end end end end end
Version data entries
57 entries across 57 versions & 2 rubygems