diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-28 16:10:16 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-28 16:10:16 -0300 |
commit | 83a437c21e1d858b109dc169788ea7ac6e708d30 (patch) | |
tree | 5d9f068c46f54e750b854ae32f537eaea3af3907 /activerecord | |
parent | 092b92f1bdddc21d92c8e60d1eb112759beb790a (diff) | |
parent | 622021cf181419109fd284c5a237018e805f05b4 (diff) | |
download | rails-83a437c21e1d858b109dc169788ea7ac6e708d30.tar.gz rails-83a437c21e1d858b109dc169788ea7ac6e708d30.tar.bz2 rails-83a437c21e1d858b109dc169788ea7ac6e708d30.zip |
Merge pull request #15390 from sgrif/sg-property-order
Maintain column order when overriding existing columns
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/properties.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/custom_properties_test.rb | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb index a51dd56bcf..c99594c823 100644 --- a/activerecord/lib/active_record/properties.rb +++ b/activerecord/lib/active_record/properties.rb @@ -88,9 +88,14 @@ module ActiveRecord private def add_user_provided_columns(schema_columns) - schema_columns.reject { |column| - user_provided_columns.key? column.name - } + user_provided_columns.values + existing_columns = schema_columns.map do |column| + user_provided_columns[column.name] || column + end + + existing_column_names = existing_columns.map(&:name) + new_columns = user_provided_columns.except(*existing_column_names).values + + existing_columns + new_columns end end end diff --git a/activerecord/test/cases/custom_properties_test.rb b/activerecord/test/cases/custom_properties_test.rb index 9910e4042c..397a8e0692 100644 --- a/activerecord/test/cases/custom_properties_test.rb +++ b/activerecord/test/cases/custom_properties_test.rb @@ -79,5 +79,10 @@ module ActiveRecord assert_equal 4.4, data.overloaded_float end + + def test_overloading_properties_does_not_change_column_order + column_names = OverloadedType.column_names + assert_equal %w(id overloaded_float unoverloaded_float overloaded_string_with_limit non_existent_decimal), column_names + end end end |