Sha256: 61b002bf72c4da21c26a359cbf2464d124ea4e9f2249bfb5835163ac8987408f

Contents?: true

Size: 1.51 KB

Versions: 48

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8
module Mongoid
  module Relations

    # This is the superclass for one to one relations and defines the common
    # behaviour or those proxies.
    class One < Proxy

      # Clear this relation - same as calling #delete on the document.
      #
      # @example Clear the relation.
      #   relation.clear
      #
      # @return [ true, false ] If the delete suceeded.
      #
      # @since 3.0.0
      def clear
        target.delete
      end

      # Get all the documents in the relation that are loaded into memory.
      #
      # @example Get the in memory documents.
      #   relation.in_memory
      #
      # @return [ Array<Document> ] The documents in memory.
      #
      # @since 2.1.0
      def in_memory
        [ target ]
      end

      # Since method_missing is overridden we should override this as well.
      #
      # @example Does the proxy respond to the method?
      #   relation.respond_to?(:name)
      #
      # @param [ Symbol ] name The method name.
      #
      # @return [ true, false ] If the proxy responds to the method.
      #
      # @since 2.1.8
      def respond_to?(name, include_private = false)
        target.respond_to?(name, include_private) || super
      end

      # Evolve the proxy document into an object id.
      #
      # @example Evolve the proxy document.
      #   proxy.__evolve_object_id__
      #
      # @return [ Object ] The proxy document's id.
      #
      # @since 4.0.0
      def __evolve_object_id__
        target._id
      end
    end
  end
end

Version data entries

48 entries across 43 versions & 3 rubygems

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