提交 3f352d04 编写于 作者: J Jeremy Kemper

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

上级 9b4f5041
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册