aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-08-23 11:05:04 +0000
committerJamis Buck <jamis@37signals.com>2005-08-23 11:05:04 +0000
commitdfe1aeb776ed9a7da8b431c7933c858d155a13c7 (patch)
tree11593565c25ad674b9fbaf7d9d17e313f0c4198c /activerecord/lib
parent211617191ed9e6bc9da1cee1bdd134c9b8c3cdfd (diff)
downloadrails-dfe1aeb776ed9a7da8b431c7933c858d155a13c7.tar.gz
rails-dfe1aeb776ed9a7da8b431c7933c858d155a13c7.tar.bz2
rails-dfe1aeb776ed9a7da8b431c7933c858d155a13c7.zip
Saving a record with two unsaved belongs_to associations pointing to the same object fails #2023 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2040 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index ffb0d5679b..d0db4469e2 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -445,10 +445,12 @@ 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)
+ if not association.nil?
+ if association.new_record?
+ association.save(true)
+ association.send(:construct_sql)
+ end
self["#{association_class_primary_key_name}"] = association.id
- association.send(:construct_sql)
end
EOF
end