Sha256: 4a80bb72c91eca5b7cfa5e1f7a7050974e10b88992ce4bc8acdbb546657ee2af
Contents?: true
Size: 1.15 KB
Versions: 84
Compression:
Stored size: 1.15 KB
Contents
# encoding: utf-8 module Mongoid module Relations module Cascading class Restrict 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 unless relation.blank? raise Errors::DeleteRestriction.new(document, metadata.name) end end end end end end
Version data entries
84 entries across 79 versions & 7 rubygems