mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Lookup the class at runtime, not when the association is built
Trying to lookup the parent class when the association is being built runs the risk of generating uninitialized constant errors because classes haven't been fully defined yet. To work around this we look up the class at runtime through the `association` method. Fixes #10197.
This commit is contained in:
parent
07e489c9a2
commit
2a89941225
1 changed files with 2 additions and 2 deletions
|
@ -71,8 +71,8 @@ module ActiveRecord::Associations::Builder
|
||||||
old_foreign_id = attribute_was(foreign_key_field)
|
old_foreign_id = attribute_was(foreign_key_field)
|
||||||
|
|
||||||
if old_foreign_id
|
if old_foreign_id
|
||||||
reflection_klass = #{reflection.klass}
|
klass = association(#{name.inspect}).klass
|
||||||
old_record = reflection_klass.find_by(reflection_klass.primary_key => old_foreign_id)
|
old_record = klass.find_by(klass.primary_key => old_foreign_id)
|
||||||
|
|
||||||
if old_record
|
if old_record
|
||||||
old_record.touch #{options[:touch].inspect if options[:touch] != true}
|
old_record.touch #{options[:touch].inspect if options[:touch] != true}
|
||||||
|
|
Loading…
Reference in a new issue