mirror of
https://github.com/github/rails.git
synced 2026-01-10 07:08:08 -05:00
Merge pull request #55 from github/3-0-github+pluck
Backport pluck to 3-0-github
This commit is contained in:
@@ -156,6 +156,15 @@ module ActiveRecord
|
||||
0
|
||||
end
|
||||
|
||||
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)}"
|
||||
end
|
||||
|
||||
klass.connection.select_all(select(column_name).to_sql).map { |attributes|
|
||||
attributes.values.first
|
||||
}
|
||||
end
|
||||
private
|
||||
|
||||
def perform_calculation(operation, column_name, options = {})
|
||||
|
||||
@@ -379,4 +379,8 @@ class CalculationsTest < ActiveRecord::TestCase
|
||||
distinct_authors_for_approved_count = Topic.group(:approved).count(:author_name, :distinct => true)[true]
|
||||
assert_equal distinct_authors_for_approved_count, 2
|
||||
end
|
||||
|
||||
def test_pluck
|
||||
assert_equal [50, 50, 50, 60, 55, 53], Account.order("id ASC").pluck(:credit_limit)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user