aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorGraeme Porteous <graeme@rgbp.co.uk>2009-07-11 20:04:18 +0200
committerEloy Duran <eloy.de.enige@gmail.com>2009-09-12 16:03:32 +0200
commitc01be9de322ba846923340e41e69821d01541610 (patch)
treee73d2aea62c53df7d1373f011ecfcd9abb70ae43 /activerecord/lib
parent3091252abaafd15bc085f0be2b17829bebb6522c (diff)
downloadrails-c01be9de322ba846923340e41e69821d01541610.tar.gz
rails-c01be9de322ba846923340e41e69821d01541610.tar.bz2
rails-c01be9de322ba846923340e41e69821d01541610.zip
Fix has_one with foreign_key and primary_key association bug which caused the associated object being lost when saving the owner. [#1756 state:resolved]
Mixed in a bit from patch by ransom-briggs. [#2813 state:resolved] Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 10dd0b4f05..75c49ecb2b 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -314,9 +314,12 @@ module ActiveRecord
if autosave && association.marked_for_destruction?
association.destroy
- elsif autosave != false && (new_record? || association.new_record? || association[reflection.primary_key_name] != id || autosave)
- association[reflection.primary_key_name] = id
- association.save(!autosave)
+ else
+ key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
+ if autosave != false && (new_record? || association.new_record? || association[reflection.primary_key_name] != key || autosave)
+ association[reflection.primary_key_name] = key
+ association.save(!autosave)
+ end
end
end
end