Skip to content
Browse files

Merge pull request #10552 from arunagw/pluck-fixed-3-2-stable

Pluck fixed 3 2 stable
  • Loading branch information...
2 parents 84c69a1 + de5b89d commit 3589181122f1a70abc1acd8c6bf41b46e2be2f5a @rafaelfranca rafaelfranca committed
View
8 activerecord/lib/active_record/relation/calculations.rb
@@ -179,13 +179,13 @@ def calculate(operation, column_name, options = {})
def pluck(column_name)
if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
- else
- column_name = column_name.to_s
end
- column_name = column_name.to_s
+ 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
View
5 activerecord/test/cases/calculations_test.rb
@@ -494,8 +494,9 @@ def test_pluck_with_qualified_column_name
end
def test_pluck_does_not_replace_select_clause
- taks_relation = Topic.select("approved, id, id AS foo_id").order(:foo_id)
- assert_equal [false, true, true, true], taks_relation.pluck(:approved)
+ taks_relation = Topic.select("approved, id, id AS foo_id").order('foo_id DESC')
+ assert_equal [4,3,2,1], taks_relation.pluck(:id)
+ assert_equal [true, true, true, false], taks_relation.pluck(:approved)
end
def test_pluck_auto_table_name_prefix

0 comments on commit 3589181

Please sign in to comment.
Something went wrong with that request. Please try again.