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 | |
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')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 5 |
2 files changed, 12 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 diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 60c31ce486..fd36c2d8ae 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -32,12 +32,17 @@ module ActiveRecord @target = obj @owner[@association_class_primary_key_name] = obj.id unless obj.new_record? + @updated = true end @loaded = true return (@target.nil? ? nil : self) end + def updated? + @updated + end + protected |