aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/properties.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-28 10:32:00 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-28 12:08:41 -0700
commit622021cf181419109fd284c5a237018e805f05b4 (patch)
tree5d9f068c46f54e750b854ae32f537eaea3af3907 /activerecord/lib/active_record/properties.rb
parent092b92f1bdddc21d92c8e60d1eb112759beb790a (diff)
downloadrails-622021cf181419109fd284c5a237018e805f05b4.tar.gz
rails-622021cf181419109fd284c5a237018e805f05b4.tar.bz2
rails-622021cf181419109fd284c5a237018e805f05b4.zip
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.
Diffstat (limited to 'activerecord/lib/active_record/properties.rb')
-rw-r--r--activerecord/lib/active_record/properties.rb11
1 files changed, 8 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