Skip to content

Instantly share code, notes, and snippets.

@grosser
Forked from semanticart/find_values.rb
Created August 15, 2010 08:13
Show Gist options
  • Save grosser/525248 to your computer and use it in GitHub Desktop.
Save grosser/525248 to your computer and use it in GitHub Desktop.
# Tag.find_values(:select => :user_id, :limit => 30) --> ["1", "3", "6"]
# Tag.find_values(:select => 'user_id, foobar', :limit => 30, :all=>true) --> [["1","A"], ["3","B"], ["6","C"]]
class ActiveRecord::Base
def self.find_values(options)
sql = self.send(:construct_finder_sql, options.except(:all))
result = connection.select_rows(sql, name)
if options[:all]
result
else
result.map{|v| v[0] }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment