aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/nested_attributes.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-09-26 00:35:39 -0400
committerJosé Valim <jose.valim@gmail.com>2010-09-27 23:11:24 +0200
commit7f743233c4e276d1799451478e6718589d270cbd (patch)
tree2522008b3c309163ec135f78d59e1eac576c0e4a /activerecord/lib/active_record/nested_attributes.rb
parent67a838574be000f329c0f340474bc9cec1aeca16 (diff)
downloadrails-7f743233c4e276d1799451478e6718589d270cbd.tar.gz
rails-7f743233c4e276d1799451478e6718589d270cbd.tar.bz2
rails-7f743233c4e276d1799451478e6718589d270cbd.zip
Fix for nested_attributes with has_many association fails when a single record is being updated.
[#5705 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/nested_attributes.rb')
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 7372ab3278..bdd940f3ee 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -377,7 +377,12 @@ module ActiveRecord
end
if attributes_collection.is_a? Hash
- attributes_collection = attributes_collection.sort_by { |index, _| index.to_i }.map { |_, attributes| attributes }
+ keys = attributes_collection.keys
+ attributes_collection = if keys.include?('id') || keys.include?(:id)
+ Array.wrap(attributes_collection)
+ else
+ attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
+ end
end
association = send(association_name)