Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v3.1.6
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (28 sloc) 0.897 kb
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
Jump to Line
Something went wrong with that request. Please try again.