From 16510d609c601aa7d466809f3073ec3313e08937 Mon Sep 17 00:00:00 2001 From: Kevin Cheng Date: Fri, 29 Jan 2016 17:44:04 -0500 Subject: 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] --- .../lib/active_record/connection_adapters/sqlite3_adapter.rb | 2 +- activerecord/lib/active_record/result.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index d32fd5ea09..baa0a29afd 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -576,7 +576,7 @@ module ActiveRecord column end else - basic_structure.to_hash + basic_structure.to_a end end 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 -- cgit v1.2.3