diff options
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/nested_attributes_test.rb | 5 |
2 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 53617059d0..69a8518ba0 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -383,7 +383,7 @@ module ActiveRecord 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 } + attributes_collection.sort_by { |i, _| i.respond_to?(:to_i) ? i.to_i : i.object_id }.map { |_, attributes| attributes } end end diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 6568eb1d18..67a9ed6cd8 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -755,6 +755,11 @@ module NestedAttributesOnACollectionAssociationTests Interest.reflect_on_association(:man).options[:inverse_of] = :interests end + def test_can_use_symbols_as_object_identifier + @pirate.attributes = { :parrots_attributes => { :foo => { :name => 'Lovely Day' }, :bar => { :name => 'Blown Away' } } } + assert_nothing_raised(NoMethodError) { @pirate.save! } + end + private def association_setter |