aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/belongs_to.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index da7e8cda3a..e0ec4392b4 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -71,8 +71,9 @@ module ActiveRecord::Associations::Builder
foreign_key_field = #{reflection.foreign_key.inspect}
if changed_attributes.key?(foreign_key_field)
reflection_klass = #{reflection.klass}
+ primary_key_field = reflection_klass.primary_key
old_foreign_id = changed_attributes[foreign_key_field]
- old_record = reflection_klass.where(foreign_key_field => old_foreign_id).first
+ old_record = reflection_klass.where(primary_key_field => old_foreign_id).first
if old_record
old_record.touch #{options[:touch].inspect if options[:touch] != true}
end