1 module ActiveRecord #:nodoc:
2 module Reflection #:nodoc:
4 module ClassMethods #:nodoc:
6 # Update the default reflection switch so that <tt>:has_many_polymorphs</tt> types get instantiated. It's not a composed method so we have to override the whole thing.
7 def create_reflection(macro, name, options, active_record)
9 when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
10 reflection = AssociationReflection.new(macro, name, options, active_record)
12 reflection = AggregateReflection.new(macro, name, options, active_record)
13 # added by has_many_polymorphs #
14 when :has_many_polymorphs
15 reflection = PolymorphicReflection.new(macro, name, options, active_record)
18 write_inheritable_hash :reflections, name => reflection
24 class PolymorphicError < ActiveRecordError #:nodoc:
29 The reflection built by the <tt>has_many_polymorphs</tt> method.
31 Inherits from ActiveRecord::Reflection::AssociationReflection.
35 class PolymorphicReflection < AssociationReflection
36 # Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection.
41 # Return the source reflection.
43 # normally is the has_many to the through model, but we return ourselves,
44 # since there isn't a real source class for a polymorphic target
48 # Set the classname of the target. Uses the join class name.
50 # normally is the classname of the association target
51 @class_name ||= options[:join_class_name]