ActiveRecord finder using :group?

I’m trying to gather and display some simple statistical data. I want
to display the number of Products created over the last month, grouped
by the day they were created. Am I on the right track as far as the
ActiveRecord finder and also how would I iterate over the results in
the view to spit out the date and the count of products for that day?
Thanks for any help.

example sql that returns count and date, grouped by the date

SELECT count(*) as total, created_at as date FROM products GROUP BY
date(created_at) HAVING created_at >= ‘2009-07-31’ and created_at <=
‘2009-08-31’;

AR finder?

@created_products = Product.find(:all, :group => “date
(created_at)”, :having => [“created_at >= ?”, 1.month.ago])

view code?

  • Date : Total

On Aug 31, 9:39 pm, JL Smith [email protected] wrote:

I’m trying to gather and display some simple statistical data. I want
to display the number of Products created over the last month, grouped
by the day they were created. Am I on the right track as far as the
ActiveRecord finder and also how would I iterate over the results in
the view to spit out the date and the count of products for that day?
Thanks for any help.

If you want to count things you’re better off using count - find
fundamentally wants to return model objects.

Fred