1
0
Fork 0
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:
Andrew White 2013-04-24 15:03:03 +01:00
parent 07e489c9a2
commit 2a89941225

View file

@ -71,8 +71,8 @@ module ActiveRecord::Associations::Builder
old_foreign_id = attribute_was(foreign_key_field)
if old_foreign_id
reflection_klass = #{reflection.klass}
old_record = reflection_klass.find_by(reflection_klass.primary_key => old_foreign_id)
klass = association(#{name.inspect}).klass
old_record = klass.find_by(klass.primary_key => old_foreign_id)
if old_record
old_record.touch #{options[:touch].inspect if options[:touch] != true}