Sha256: eb970ad6e99191009da12e3fc66dfba7b084c0f9707dfee57456c3cca033e993

Contents?: true

Size: 1000 Bytes

Versions: 59

Compression:

Stored size: 1000 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Relations

    # This module contains the behaviour for handling polymorphic relational
    # associations.
    module Polymorphic
      extend ActiveSupport::Concern

      included do
        class_attribute :polymorphic
      end

      module ClassMethods

        # Attempts to set up the information needed to handle a polymorphic
        # relation, if the metadata checks out.
        #
        # @example Set up the polymorphic information.
        #   Movie.polymorph(metadata)
        #
        # @param [ Metadata ] metadata The relation metadata.
        #
        # @return [ Class ] The class being set up.
        #
        # @since 2.0.0.rc.1
        def polymorph(metadata)
          if metadata.polymorphic?
            self.polymorphic = true
            if metadata.relation.stores_foreign_key?
              field(metadata.inverse_type, type: String)
            end
          end
          self
        end
      end
    end
  end
end

Version data entries

59 entries across 54 versions & 6 rubygems

Version Path
mongoid-5.2.0 lib/mongoid/relations/polymorphic.rb
mongoid-5.2.0.rc0 lib/mongoid/relations/polymorphic.rb
mongoid-6.1.0.rc0 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.3 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.6 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.2 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.1 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.5 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.0 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.4 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.0.rc0 lib/mongoid/relations/polymorphic.rb
mongoid-6.0.0.beta lib/mongoid/relations/polymorphic.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-5.1.3/lib/mongoid/relations/polymorphic.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/relations/polymorphic.rb
mongoid-5.1.3 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.2 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.1 lib/mongoid/relations/polymorphic.rb
mongoid-5.1.0 lib/mongoid/relations/polymorphic.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mongoid-5.0.1/lib/mongoid/relations/polymorphic.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mongoid-5.0.2/lib/mongoid/relations/polymorphic.rb