1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Maintain column order when overriding existing columns

Working towards re-implementing serialized attributes to use the
properties API exposed the need for this, as serializing a column
shouldn't change the order of the columns.
This commit is contained in:
Sean Griffin 2014-05-28 10:32:00 -07:00
parent 092b92f1bd
commit 622021cf18
2 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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