method
resolve_sti_reflections
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: PrimaryKeyError
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
resolve_sti_reflections()
public
Hide source
# File activerecord/lib/active_record/fixture_set/table_row.rb, line 148 def resolve_sti_reflections # If STI is used, find the correct subclass for association reflection reflection_class._reflections.each_value do |association| case association.macro when :belongs_to # Do not replace association name with association foreign key if they are named the same fk_name = association.join_foreign_key if association.name.to_s != fk_name && value = @row.delete(association.name.to_s) if association.polymorphic? if value.sub!(/\s*\(([^)]*)\)\s*$/, "") # support polymorphic belongs_to as "label (Type)" @row[association.join_foreign_type] = $1 end elsif association.join_primary_key != association.klass.primary_key raise PrimaryKeyError.new(@label, association, value) end if fk_name.is_a?(Array) composite_key = ActiveRecord::FixtureSet.composite_identify(value, fk_name) composite_key.each do |column, value| next if column_defined?(column) @row[column] = value end else fk_type = reflection_class.type_for_attribute(fk_name).type @row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type) end end when :has_many if association.options[:through] add_join_records(HasManyThroughProxy.new(association)) end end end end