Sha256: 9e15cc73c0e6ff3e5c36eb586e226184ad1fc977baa17f1d7f21f68ce3047f6b

Contents?: true

Size: 1.04 KB

Versions: 170

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:

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

      included do
        class_attribute :polymorphic
      end

      module ClassMethods #:nodoc:

        # 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)
          tap do |klass|
            if metadata.polymorphic?
              klass.polymorphic = true
              if metadata.relation.stores_foreign_key?
                field(metadata.inverse_type, :type => String)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

170 entries across 78 versions & 4 rubygems

Version Path
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.8 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/polymorphic.rb
classiccms-0.5.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/polymorphic.rb