Class: ActiveRecord::Associations::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/store_base_sti_class_for_3_1.rb

Instance Method Summary collapse

Instance Method Details

#creation_attributesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/store_base_sti_class_for_3_1.rb', line 14

def creation_attributes
  attributes = {}

  if reflection.macro.in?([:has_one, :has_many]) && !options[:through]
    attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key]

    if reflection.options[:as]
      # START PATCH
      # original:
      # attributes[reflection.type] = owner.class.base_class.name
      
      attributes[reflection.type] = ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name
      
      # END PATCH
    end
  end

  attributes
end