aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/nested_attributes.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2011-02-15 12:01:04 -0300
committerEmilio Tagua <miloops@gmail.com>2011-02-15 12:01:04 -0300
commit8ee0b4414890f919594c1a388d987b5b7364a505 (patch)
tree6c6c6aa19da0eb8066d2f0b9b02b08f2cc696c29 /activerecord/lib/active_record/nested_attributes.rb
parent348c0ec7c656b3691aa4e687565d28259ca0f693 (diff)
parentc9f1ab5365319e087e1b010a3f90626a2b8f080b (diff)
downloadrails-8ee0b4414890f919594c1a388d987b5b7364a505.tar.gz
rails-8ee0b4414890f919594c1a388d987b5b7364a505.tar.bz2
rails-8ee0b4414890f919594c1a388d987b5b7364a505.zip
Merge remote branch 'rails/master' into identity_map
Conflicts: activerecord/examples/performance.rb activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/nested_attributes.rb activerecord/test/cases/relations_test.rb
Diffstat (limited to 'activerecord/lib/active_record/nested_attributes.rb')
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 0a073ad6c8..52bdadcbb4 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -410,8 +410,20 @@ module ActiveRecord
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
end
elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
+ unless association.loaded? || call_reject_if(association_name, attributes)
+ # Make sure we are operating on the actual object which is in the association's
+ # proxy_target array (either by finding it, or adding it if not found)
+ target_record = association.proxy_target.detect { |record| record == existing_record }
+
+ if target_record
+ existing_record = target_record
+ else
+ association.send(:add_to_target, existing_record)
+ end
+
+ end
+
if !call_reject_if(association_name, attributes)
- association.send(:add_record_to_target_with_callbacks, existing_record) if !association.loaded?
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
end
else