diff options
author | Szetobo <szetobo@gmail.com> | 2010-07-12 09:47:47 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-21 14:25:27 +0200 |
commit | 0057d2df71ec7c2a788acd3b4bade263fc0fe361 (patch) | |
tree | 786e912e4da78b5f86ec16f8fbec9b6499c3b7e7 /activerecord/lib/active_record | |
parent | c0bfa0bfc17f4aa615cd9d1006509e0d84b5692d (diff) | |
download | rails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.tar.gz rails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.tar.bz2 rails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.zip |
association load target shouldn't replace records
from db if it is already loaded by nested attributes assignment
[#5053 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 7100be0245..692badcc5c 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -396,11 +396,12 @@ module ActiveRecord if @target.is_a?(Array) && @target.any? @target = find_target.map do |f| i = @target.index(f) - t = @target.delete_at(i) if i - if t && t.changed? + if i + t = @target.delete_at(i) + keys = ["id"] + t.changes.keys + (f.attribute_names - t.attribute_names) + t.attributes = f.attributes.except(*keys) t else - f.mark_for_destruction if t && t.marked_for_destruction? f end end + @target |