diff options
author | Jamis Buck <jamis@37signals.com> | 2005-09-20 16:12:13 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-09-20 16:12:13 +0000 |
commit | 5213a1f73332995ae98d2a163454dff2b288e650 (patch) | |
tree | 45b4d6979c5812e4ea2208971de15a1827bcc9d9 /activerecord/lib/active_record/associations.rb | |
parent | 4fa9a2bfe22515f893368786982dd6e76241b552 (diff) | |
download | rails-5213a1f73332995ae98d2a163454dff2b288e650.tar.gz rails-5213a1f73332995ae98d2a163454dff2b288e650.tar.bz2 rails-5213a1f73332995ae98d2a163454dff2b288e650.zip |
Fixed saving a record with two unsaved belongs_to associations pointing to the same object #2023 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2278 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 23ccb34cd2..b2a2ed6e11 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -449,11 +449,13 @@ module ActiveRecord module_eval do before_save <<-EOF association = instance_variable_get("@#{association_name}") - if not association.nil? and association.new_record? - association.save(true) - self["#{association_class_primary_key_name}"] = association.id - association.send(:construct_sql) - end + if not association.nil? + if association.new_record? + association.save(true) + association.send(:construct_sql) + end + self["#{association_class_primary_key_name}"] = association.id if association.updated? + end EOF end |