From 08ef06dbf1273fc09d6e23b7d8727928717e8004 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 7 Feb 2011 16:25:22 -0800 Subject: just return the record from insert_record, use truthiness for comparisons --- .../lib/active_record/associations/has_many_through_association.rb | 4 ++-- activerecord/lib/active_record/autosave_association.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 81dd373f7b..f299f51466 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -26,14 +26,14 @@ module ActiveRecord def insert_record(record, force = true, validate = true) if record.new_record? - return false unless save_record(record, force, validate) + return unless save_record(record, force, validate) end through_association = @owner.send(@reflection.through_reflection.name) through_association.create!(construct_join_attributes(record)) update_counter(1) - true + record end private diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 9c7bb67479..c52af23fbd 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -306,6 +306,8 @@ module ActiveRecord records.each do |record| next if record.destroyed? + saved = true + if autosave && record.marked_for_destruction? association.destroy(record) elsif autosave != false && (@new_record_before_save || record.new_record?) @@ -318,7 +320,7 @@ module ActiveRecord saved = record.save(:validate => false) end - raise ActiveRecord::Rollback if saved == false + raise ActiveRecord::Rollback unless saved end end -- cgit v1.2.3