aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_collection.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-24 23:30:11 +0000
committerJon Leighton <j@jonathanleighton.com>2011-01-30 11:58:08 +0000
commit88df88095c82cde53501abe2a44f6c1f66c272b4 (patch)
tree22b2b27bd4c735b23bcdf10da16d14df4f479072 /activerecord/lib/active_record/associations/association_collection.rb
parent1da1ac159f9391b9a053a0fb0d426499b9edd5b7 (diff)
downloadrails-88df88095c82cde53501abe2a44f6c1f66c272b4.tar.gz
rails-88df88095c82cde53501abe2a44f6c1f66c272b4.tar.bz2
rails-88df88095c82cde53501abe2a44f6c1f66c272b4.zip
AssociationCollection#to_ary should definitely dup the target! Also changed #replace which was previously incorrect, but the test passed due to the fact that to_a was not duping.
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 7504773639..f2997b9db3 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -45,7 +45,7 @@ module ActiveRecord
end
def to_ary
- load_target
+ load_target.dup
end
alias_method :to_a, :to_ary
@@ -289,13 +289,13 @@ module ActiveRecord
# This will perform a diff and delete/add only records that have changed.
def replace(other_array)
other_array.each { |val| raise_on_type_mismatch(val) }
-
- load_target
+ original_target = load_target.dup
transaction do
delete(@target - other_array)
unless concat(other_array - @target)
+ @target = original_target
raise RecordNotSaved, "Failed to replace #{@reflection.name} because one or more of the "
"new records could not be saved."
end