aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShintaro Kojima <goodies@codeout.net>2015-04-04 12:24:48 +0000
committerShintaro Kojima <goodies@codeout.net>2015-04-04 12:48:36 +0000
commite646d3bf574ad3ea7dc5b525511377559b2640dc (patch)
tree3683452896a028a7e3014783b3c9016328a08b5d
parent5abadf1613710c6e6b54e8190b66543861711b8a (diff)
downloadrails-e646d3bf574ad3ea7dc5b525511377559b2640dc.tar.gz
rails-e646d3bf574ad3ea7dc5b525511377559b2640dc.tar.bz2
rails-e646d3bf574ad3ea7dc5b525511377559b2640dc.zip
Fix a regression introduced by removing unnecessary db call when replacing
When replacing a has_many association with the same one, there is nothing to do with database but a setter method should still return the substituted value for backward compatibility.
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb2
2 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 88531205a1..6caadb4ce8 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -370,6 +370,8 @@ module ActiveRecord
replace_common_records_in_memory(other_array, original_target)
if other_array != original_target
transaction { replace_records(other_array, original_target) }
+ else
+ other_array
end
end
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 290b2a0d6b..171cfbde44 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1503,6 +1503,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_queries(0, ignore_none: true) do
firm.clients = []
end
+
+ assert_equal [], firm.send('clients=', [])
end
def test_transactions_when_replacing_on_persisted