From 93076168c4d2209e007a32abc7142cc23782d56a Mon Sep 17 00:00:00 2001 From: twinturbo Date: Mon, 30 Apr 2012 09:45:00 -0700 Subject: Add ActiveRecord::Base#ids --- activerecord/lib/active_record/relation/calculations.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index db894c8aa9..f388b75c05 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -139,6 +139,16 @@ module ActiveRecord end end + # Pluck all the ID's for the relation using the table's primary key + # + # Examples: + # + # Person.ids # SELECT people.id FROM people + # Person.joins(:companies).ids # SELECT people.id FROM PEOPLE INNER JOIN companies ON companies.person_id = people.id + def ids + pluck primary_key + end + private def perform_calculation(operation, column_name, options = {}) -- cgit v1.2.3