aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@aura-online.co.uk>2010-06-12 11:55:31 +0100
committerJosé Valim <jose.valim@gmail.com>2010-06-20 00:32:06 +0200
commitf664c57fe854c230d25c448b941569b81860fa79 (patch)
treeabec332dc7b0981c9ee43090b7aacbe1827fbdf1 /activerecord/lib/active_record/associations
parent98a5188f518b1e8cfa9d7aa59856e5b32985eb46 (diff)
downloadrails-f664c57fe854c230d25c448b941569b81860fa79.tar.gz
rails-f664c57fe854c230d25c448b941569b81860fa79.tar.bz2
rails-f664c57fe854c230d25c448b941569b81860fa79.zip
Don't overwrite unsaved updates when loading an association but preserve the order of the loaded records. Reapplied from before but now allows already-saved records to be refreshed.
[#4830 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index d9903243ce..bd67516518 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -388,7 +388,11 @@ module ActiveRecord
begin
if !loaded?
if @target.is_a?(Array) && @target.any?
- @target = find_target + @target.find_all {|t| t.new_record? }
+ @target = find_target.map do |f|
+ i = @target.index(f)
+ t = @target.delete_at(i) if i
+ (t && t.changed?) ? t : f
+ end + @target
else
@target = find_target
end