aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-28 16:10:16 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-28 16:10:16 -0300
commit83a437c21e1d858b109dc169788ea7ac6e708d30 (patch)
tree5d9f068c46f54e750b854ae32f537eaea3af3907 /activerecord/lib
parent092b92f1bdddc21d92c8e60d1eb112759beb790a (diff)
parent622021cf181419109fd284c5a237018e805f05b4 (diff)
downloadrails-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/lib')
-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