Sha256: 5bdfba5619c0019ef142ae48cc7501e77d111246cb40989cc846c0ae0e363508

Contents?: true

Size: 954 Bytes

Versions: 29

Compression:

Stored size: 954 Bytes

Contents

module ActiveRecord
  # = Active Record Belongs To Polymorphic Association
  module Associations
    class BelongsToPolymorphicAssociation < BelongsToAssociation #:nodoc:
      def klass
        type = owner[reflection.foreign_type]
        type.presence && type.constantize
      end

      private

        def replace_keys(record)
          super
          owner[reflection.foreign_type] = record && record.class.base_class.name
        end

        def different_target?(record)
          super || record.class != klass
        end

        def inverse_reflection_for(record)
          reflection.polymorphic_inverse_of(record.class)
        end

        def raise_on_type_mismatch!(record)
          # A polymorphic association cannot have a type mismatch, by definition
        end

        def stale_state
          foreign_key = super
          foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s]
        end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
activerecord-4.0.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.1.rc4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.1.rc3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.1.rc2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.1.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
challah-1.0.0 vendor/bundle/gems/activerecord-4.0.0/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.0 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.0.rc2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.0.0.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb