Module: Mongoid::Relations::Polymorphic::ClassMethods

Defined in:
lib/mongoid/relations/polymorphic.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#polymorph(metadata) ⇒ Class

Attempts to set up the information needed to handle a polymorphic relation, if the metadata checks out.

Examples:

Set up the polymorphic information.

Movie.polymorph()

Parameters:

  • metadata (Metadata)

    The relation metadata.

Returns:

  • (Class)

    The class being set up.

Since:

  • 2.0.0.rc.1



27
28
29
30
31
32
33
34
35
36
# File 'lib/mongoid/relations/polymorphic.rb', line 27

def polymorph()
  tap do |klass|
    if .polymorphic?
      klass.polymorphic = true
      if .relation.stores_foreign_key?
        field(.inverse_type, :type => String)
      end
    end
  end
end