Skip to content

Instantly share code, notes, and snippets.

@dnch
Created January 30, 2009 02:53
Show Gist options
  • Save dnch/54915 to your computer and use it in GitHub Desktop.
Save dnch/54915 to your computer and use it in GitHub Desktop.
class Foo < ActiveRecord::Base
end
result_set = Foo.find_calculations(:conditions => ["active = ?", true]) do
sum :field_one, :as => "sum_of_field_one"
count :field_four
max :field_one
min :field_one
mean :field_eight
end
result_set[:sum_of_field_one] # => 53
result_set[:field_four_count] # => 11
result_set[:field_one_max] # => 1535
result_set[:field_two_max] # => 144
result_set[:field_eight_mean] # => 94.314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment