ActiveRecord Calculations 4

Posted by Bob Silva Sun, 05 Nov 2006 20:38:00 GMT

I've been wanting to modify the ActiveRecord Calculations module to support multiple aggregate calculations in one query for awhile now. My current project with lots of graphing finally gave me the motivation to do it. Refer to the patch for details and feel free to comment on it.
# Calculate different aggregate functions at once
min, max = Person.calculate(:min, :age, :max, :age)

# Specify the column aliases so you can order by it
views, replies = Posts.sum({:views => 'number_of_views'}, :replies, :order => "number_of_views desc") 
Multiple Calculations Patch

Comments

Leave a response

  1. Mike Sax about 4 hours later:
    Hi Bob, very cooll... so what are you using for graphing? Gruff? I'll have to do graphing pretty soon and it doesn't like there are many options out there.
  2. Bob Silva about 7 hours later:
    I use the Ruby bindings with ASE ChartDirector at http://www.advsofteng.com/
  3. Bill Shobe about 1 month later:
    I would love to try this. How do I use the .diff file? Thanks.
  4. Eric 4 months later:
    Hi! Is this still possible to use this patch with Rails 1.2?
Comments