diff options
author | Eloy Duran <eloy.de.enige@gmail.com> | 2009-03-17 01:04:47 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-04-27 19:25:27 +0100 |
commit | da3c21ead59cb47b8f4c69c6bd95f225a9c8b479 (patch) | |
tree | 511c5096c73edf80f3efc9264ea353ab680b386e /activerecord/lib | |
parent | 21aa32692caf91f56d1c5c411baae635fa398344 (diff) | |
download | rails-da3c21ead59cb47b8f4c69c6bd95f225a9c8b479.tar.gz rails-da3c21ead59cb47b8f4c69c6bd95f225a9c8b479.tar.bz2 rails-da3c21ead59cb47b8f4c69c6bd95f225a9c8b479.zip |
Ensure the parent record is always saved when the child is invalid. [#2249 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 741aa2acbe..9717ca3d8b 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -311,11 +311,13 @@ module ActiveRecord # ActiveRecord::Base after the AutosaveAssociation module, which it does by default. def save_has_one_association(reflection) if (association = association_instance_get(reflection.name)) && !association.target.nil? - if reflection.options[:autosave] && association.marked_for_destruction? + autosave = reflection.options[:autosave] + + if autosave && association.marked_for_destruction? association.destroy - elsif new_record? || association.new_record? || association[reflection.primary_key_name] != id || reflection.options[:autosave] + elsif new_record? || association.new_record? || association[reflection.primary_key_name] != id || autosave association[reflection.primary_key_name] = id - association.save(false) + association.save(!autosave) end end end @@ -330,10 +332,12 @@ module ActiveRecord # ActiveRecord::Base after the AutosaveAssociation module, which it does by default. def save_belongs_to_association(reflection) if association = association_instance_get(reflection.name) - if reflection.options[:autosave] && association.marked_for_destruction? + autosave = reflection.options[:autosave] + + if autosave && association.marked_for_destruction? association.destroy else - association.save(false) if association.new_record? || reflection.options[:autosave] + association.save(!autosave) if association.new_record? || autosave if association.updated? self[reflection.primary_key_name] = association.id |