aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-02-10 08:20:54 -0700
committerSean Griffin <sean@thoughtbot.com>2015-02-10 08:21:46 -0700
commit2f8c596d1beb46acd8a74f0e6d5c1c48a29dcee9 (patch)
tree0915ec2f0975e4bb98b26e43475562dbed34261c /activerecord/lib
parentd89912b9bef03f76f355e807476edd292cc293bc (diff)
downloadrails-2f8c596d1beb46acd8a74f0e6d5c1c48a29dcee9.tar.gz
rails-2f8c596d1beb46acd8a74f0e6d5c1c48a29dcee9.tar.bz2
rails-2f8c596d1beb46acd8a74f0e6d5c1c48a29dcee9.zip
Maintain a consistent order in `ActiveRecord::Base#attributes`
Fixes #18871
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_set/builder.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_set/builder.rb b/activerecord/lib/active_record/attribute_set/builder.rb
index 0f3c285a80..e85777c335 100644
--- a/activerecord/lib/active_record/attribute_set/builder.rb
+++ b/activerecord/lib/active_record/attribute_set/builder.rb
@@ -20,7 +20,7 @@ module ActiveRecord
end
class LazyAttributeHash # :nodoc:
- delegate :select, :transform_values, :each_key, to: :materialize
+ delegate :transform_values, :each_key, to: :materialize
def initialize(types, values, additional_types)
@types = types
@@ -50,6 +50,16 @@ module ActiveRecord
super
end
+ def select
+ keys = types.keys | values.keys | delegate_hash.keys
+ keys.each_with_object({}) do |key, hash|
+ attribute = self[key]
+ if yield(key, attribute)
+ hash[key] = attribute
+ end
+ end
+ end
+
protected
attr_reader :types, :values, :additional_types, :delegate_hash