From de5b89ddc9f9f45760856a1eb55f53a11d067a74 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 10 May 2013 15:41:51 +0200 Subject: Fixed pluck to be working with selects. See #9777 for details. Previously pluck is not returning what we wanted to Added a test also to make sure it's working fine. This will also fix the build for 1.8.7 as we were doing some sort on hash. Thanks @pixeltrix for helping me out. Thanks @linduxed for pairing with me. --- activerecord/lib/active_record/relation/calculations.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index dddd1f46a1..d4765a6782 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -181,8 +181,11 @@ module ActiveRecord column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}" end + result = klass.connection.exec_query(select(column_name).to_sql) + last_column = result.columns.last + klass.connection.select_all(select(column_name).arel).map! do |attributes| - klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes)) + klass.type_cast_attribute(last_column, klass.initialize_attributes(attributes)) end end -- cgit v1.2.3