From 622021cf181419109fd284c5a237018e805f05b4 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 28 May 2014 10:32:00 -0700 Subject: 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. --- activerecord/lib/active_record/properties.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/properties.rb') 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 -- cgit v1.2.3