aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/nested_attributes.rb
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-10-15 16:27:48 -0300
committerEmilio Tagua <miloops@gmail.com>2010-11-19 19:08:55 -0300
commit333cdcdf5ae42b6c6625f2fd29ae7814ec75d5bf (patch)
tree0ad7a7f63adb4bc634682a1c053edad302ab8166 /activerecord/lib/active_record/nested_attributes.rb
parent08c37b7ed8281bc3e3c1eca98a4859017c89157a (diff)
downloadrails-333cdcdf5ae42b6c6625f2fd29ae7814ec75d5bf.tar.gz
rails-333cdcdf5ae42b6c6625f2fd29ae7814ec75d5bf.tar.bz2
rails-333cdcdf5ae42b6c6625f2fd29ae7814ec75d5bf.zip
Bring back "Reject attributes even if association is loaded" after rebasing to master.
Diffstat (limited to 'activerecord/lib/active_record/nested_attributes.rb')
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 93c0ca52e3..9d7c162798 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -399,10 +399,17 @@ module ActiveRecord
unless reject_new_record?(association_name, attributes)
association.build(attributes.except(*UNASSIGNABLE_KEYS))
end
+ elsif existing_records.count == 0 #Existing record but not yet associated
+ existing_record = self.class.reflect_on_association(association_name).klass.find(attributes['id'])
+ 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
elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
- association.send(:add_record_to_target_with_callbacks, existing_record) if !association.loaded? && !call_reject_if(association_name, attributes)
- assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
-
+ 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
raise_nested_attributes_record_not_found(association_name, attributes['id'])
end