Sha256: 5faf2b7e501cd45d21458cd1ff84e7d9b38d113c4b643d9591a2d5de9f156ef3

Contents?: true

Size: 1.56 KB

Versions: 27

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Association

    # This is the superclass for one to one relations and defines the common
    # behavior or those proxies.
    class One < Association::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

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/association/one.rb
mongoid-7.3.4 lib/mongoid/association/one.rb
mongoid-7.1.11 lib/mongoid/association/one.rb
mongoid-7.2.6 lib/mongoid/association/one.rb
mongoid-7.3.3 lib/mongoid/association/one.rb
mongoid-7.3.2 lib/mongoid/association/one.rb
mongoid-7.2.5 lib/mongoid/association/one.rb
mongoid-7.1.10 lib/mongoid/association/one.rb
mongoid-7.1.9 lib/mongoid/association/one.rb
mongoid-7.2.4 lib/mongoid/association/one.rb
mongoid-7.3.1 lib/mongoid/association/one.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/association/one.rb
mongoid-7.3.0 lib/mongoid/association/one.rb
mongoid-7.2.3 lib/mongoid/association/one.rb
mongoid-7.1.8 lib/mongoid/association/one.rb
mongoid-7.2.2 lib/mongoid/association/one.rb
mongoid-7.2.1 lib/mongoid/association/one.rb
mongoid-7.1.7 lib/mongoid/association/one.rb
mongoid-7.2.0 lib/mongoid/association/one.rb
mongoid-7.1.6 lib/mongoid/association/one.rb