Sha256: 58b17574c060a9c75230faed078aded595acb1d1780301aba04f28970919efb8

Contents?: true

Size: 1.02 KB

Versions: 148

Compression:

Stored size: 1.02 KB

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.class.base_class.name
        end

        def remove_keys
          super
          owner[reflection.foreign_type] = nil
        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

148 entries across 143 versions & 10 rubygems

Version Path
activerecord-4.2.11.3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.2.11.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.7 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.7.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.6.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.0.7.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.2.11.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.6.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.0.7.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.2.11 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.6 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.0.7 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.5 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.5.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.2.10 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-4.2.10.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.0.6 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.1.4.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-5.0.6.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb