Sha256: 1e149ddcf01b2c634325423ab62cb1df6616453524069e77c7f0dc71fa46963e

Contents?: true

Size: 1018 Bytes

Versions: 91

Compression:

Stored size: 1018 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Relations
    module Cascading
      class Nullify

        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

        # This cascade does not delete the referenced relations, but instead
        # sets the foreign key values to nil.
        #
        # @example Nullify the reference.
        #   strategy.cascade
        def cascade
          relation.nullify if relation
        end
      end
    end
  end
end

Version data entries

91 entries across 86 versions & 7 rubygems

Version Path
mongoid-6.4.8 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.7 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.5 lib/mongoid/relations/cascading/nullify.rb
mongoid-5.4.1 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.4 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.2 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.1 lib/mongoid/relations/cascading/nullify.rb
mongoid-5.4.0 lib/mongoid/relations/cascading/nullify.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/relations/cascading/nullify.rb
mongoid-6.4.0 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.3.0 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.2.1 lib/mongoid/relations/cascading/nullify.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.2.0/lib/mongoid/relations/cascading/nullify.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/relations/cascading/nullify.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/relations/cascading/nullify.rb
mongoid-6.2.0 lib/mongoid/relations/cascading/nullify.rb
mongoid-6.1.1 lib/mongoid/relations/cascading/nullify.rb
mongoid-5.2.1 lib/mongoid/relations/cascading/nullify.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/relations/cascading/nullify.rb
mongoid-6.1.0 lib/mongoid/relations/cascading/nullify.rb