aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
diff options
context:
space:
mode:
authorKevin Cheng <Kache@users.noreply.github.com>2016-01-29 17:44:04 -0500
committerGannon McGibbon <gannon.mcgibbon@shopify.com>2018-09-18 16:40:10 -0400
commit16510d609c601aa7d466809f3073ec3313e08937 (patch)
treea7f1ccbc273008772d6611d9f882acb853aa4f8a /activerecord/lib/active_record/result.rb
parente925cb4d856088a815bf4a0cf27518d01bb4029d (diff)
downloadrails-16510d609c601aa7d466809f3073ec3313e08937.tar.gz
rails-16510d609c601aa7d466809f3073ec3313e08937.tar.bz2
rails-16510d609c601aa7d466809f3073ec3313e08937.zip
Deprecate ActiveRecord::Result#to_hash in favor of #to_a
method returns an array of hashes, not a hash e.g. Hash.try_convert(result) calls #to_hash and raises a TypeError [Gannon McGibbon + Kevin Cheng]
Diffstat (limited to 'activerecord/lib/active_record/result.rb')
-rw-r--r--activerecord/lib/active_record/result.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index 3b2556b1c8..453331e163 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -21,7 +21,7 @@ module ActiveRecord
# ]
#
# # Get an array of hashes representing the result (column => value):
- # result.to_hash
+ # result.to_a
# # => [{"id" => 1, "title" => "title_1", "body" => "body_1"},
# {"id" => 2, "title" => "title_2", "body" => "body_2"},
# ...
@@ -66,10 +66,18 @@ module ActiveRecord
end
# Returns an array of hashes representing each row record.
- def to_hash
+ def to_a
hash_rows
end
+ def to_hash
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ `ActiveRecord::Result#to_hash` has been renamed to `to_a`.
+ `to_hash` is deprecated and will be removed in Rails 6.1.
+ MSG
+ to_a
+ end
+
alias :map! :map
alias :collect! :map