Sha256: 2c6f1f9a1f9886533c376c3cae1dbb8f711fe254a6e193e20aecccad8c617a1f

Contents?: true

Size: 905 Bytes

Versions: 5

Compression:

Stored size: 905 Bytes

Contents

module ActiveRecord
  # = Active Record Belongs To Polymorphic Association
  module Associations
    class BelongsToPolymorphicAssociation < BelongsToAssociation #:nodoc:
      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 klass
          type = owner[reflection.foreign_type]
          type.presence && type.constantize
        end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-3.1.0.rc5 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.1.0.rc4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.1.0.rc3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.1.0.rc2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.1.0.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb