Sha256: 83268fbd631f491023b52f9d1b6c92ff67b50abcafa2483e19cfc8f4de62f706

Contents?: true

Size: 953 Bytes

Versions: 27

Compression:

Stored size: 953 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

27 entries across 22 versions & 3 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/activerecord-3.2.22.5/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22.5 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22.4 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22.3 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22.2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22.1 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.22 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.21 lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.20 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.19 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.18 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.17 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.16 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.15 lib/active_record/associations/belongs_to_polymorphic_association.rb