Module: ActiveRecord::Reflection::ClassMethods

Defined in:
lib/has_many_polymorphs/reflection.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#create_reflection(macro, name, options, active_record) ⇒ Object

Update the default reflection switch so that :has_many_polymorphs types get instantiated. It’s not a composed method so we have to override the whole thing.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/has_many_polymorphs/reflection.rb', line 8

def create_reflection(macro, name, options, active_record)
  case macro
    when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
      klass = options[:through] ? ThroughReflection : AssociationReflection
      reflection = klass.new(macro, name, options, active_record)
    when :composed_of
      reflection = AggregateReflection.new(macro, name, options, active_record)
    # added by has_many_polymorphs #
    when :has_many_polymorphs
      reflection = PolymorphicReflection.new(macro, name, options, active_record)
  end
  write_inheritable_hash :reflections, name => reflection
  reflection
end