diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-24 15:03:03 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-24 15:07:39 +0100 |
commit | 2a8994122588a2bafb8cf052f2ca1a49a2b758d6 (patch) | |
tree | 89b366ff107c0ba025332be1d91b3f8c23330139 | |
parent | 07e489c9a2b1a4c359a8fc494c2e7b4af17a0e37 (diff) | |
download | rails-2a8994122588a2bafb8cf052f2ca1a49a2b758d6.tar.gz rails-2a8994122588a2bafb8cf052f2ca1a49a2b758d6.tar.bz2 rails-2a8994122588a2bafb8cf052f2ca1a49a2b758d6.zip |
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.
-rw-r--r-- | activerecord/lib/active_record/associations/builder/belongs_to.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 092230b2f7..543a0247d1 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -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} |