Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restore support for Model.pluck('sql fragment')

  • Loading branch information...
commit 3f352d040575c9a08d13e10fd6191fbf2fa674ba 1 parent 9b4f504
Jeremy Kemper jeremy authored
3  activerecord/lib/active_record/relation/calculations.rb
View
@@ -130,7 +130,8 @@ def pluck(column_name)
column = types[key]
result.map do |attributes|
- value = klass.initialize_attributes(attributes)[key]
+ raise ArgumentError, "Pluck expects to select just one attribute: #{attributes.inspect}" unless attributes.one?
+ value = klass.initialize_attributes(attributes).first[1]
if column
column.type_cast value
else
8 activerecord/test/cases/calculations_test.rb
View
@@ -466,6 +466,14 @@ def test_pluck_not_auto_table_name_prefix_if_column_joined
assert_equal [7], Company.joins(:contracts).pluck(:developer_id)
end
+ def test_pluck_with_selection_clause
+ assert_equal [50, 53, 55, 60], Account.pluck('DISTINCT credit_limit').sort
+ end
+
+ def test_pluck_expects_a_single_selection
+ assert_raise(ArgumentError) { Account.pluck 'id, credit_limit' }
+ end
+
def test_plucks_with_ids
assert_equal Company.all.map(&:id).sort, Company.ids.sort
end
Please sign in to comment.
Something went wrong with that request. Please try again.