Sha256: 700c9612f6ee058c90709c4febe3d27c3e1168116ed991c9371e2f207328a409
Contents?: true
Size: 1.12 KB
Versions: 106
Compression:
Stored size: 1.12 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 def cascade Array.wrap(relation).each { |doc| doc.delete } if relation end end end end end
Version data entries
106 entries across 60 versions & 3 rubygems