aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorNathaniel Talbott <nathaniel@terralien.com>2008-09-19 16:42:18 -0400
committerMichael Koziarski <michael@koziarski.com>2008-09-20 14:16:43 +0200
commit9d7f186f746f38367851355fcd301ac24d6f6a51 (patch)
tree4d76a352538ea823b99b27abd9c5efc678fe0b87 /activerecord/lib/active_record
parent79f55de9c5e3ff1f8d9e767c5af21ba31be4cfba (diff)
downloadrails-9d7f186f746f38367851355fcd301ac24d6f6a51.tar.gz
rails-9d7f186f746f38367851355fcd301ac24d6f6a51.tar.bz2
rails-9d7f186f746f38367851355fcd301ac24d6f6a51.zip
Fixed an error triggered by a reload followed by a foreign key assignment.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5d91315aad..d7aa4bfa98 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1268,7 +1268,11 @@ module ActiveRecord
if association_proxy_class == BelongsToAssociation
define_method("#{reflection.primary_key_name}=") do |target_id|
- instance_variable_get(ivar).reset if instance_variable_defined?(ivar)
+ if instance_variable_defined?(ivar)
+ if association = instance_variable_get(ivar)
+ association.reset
+ end
+ end
write_attribute(reflection.primary_key_name, target_id)
end
end