Sha256: 88833218b92bfe503cd15dcf77ea4cd932180977881ebbd64cdda2213a71e81f

Contents?: true

Size: 897 Bytes

Versions: 161

Compression:

Stored size: 897 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
          [super, owner[reflection.foreign_type].to_s]
        end
    end
  end
end

Version data entries

161 entries across 135 versions & 13 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
swipe-rails-0.0.5 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb
challah-1.0.0.beta3 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
challah-1.0.0.beta2 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
challah-1.0.0.beta vendor/bundle/gems/activerecord-3.2.11/lib/active_record/associations/belongs_to_polymorphic_association.rb
challah-1.0.0.beta vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.13 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.1.12 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.13.rc2 lib/active_record/associations/belongs_to_polymorphic_association.rb
activerecord-3.2.13.rc1 lib/active_record/associations/belongs_to_polymorphic_association.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/belongs_to_polymorphic_association.rb