I'm doing some statics calculation in my product. A user has performed a number of operations, let's say posted comments. I want to be able to show them how many comments they've posted per week for the past month, or per month for the past year.
Is there any way with activerecord to group this way? Is my best best to simply do this manually - to iterate over the records summing based on my own criteria?
class User < ActiveRecord::Base
has_many :comments
end
class Comments < ActiveRecord::Base
belongs_to :user
end
@user.comments(:all).map {|c| ...do my calculations here...}
or is there some better way?
thanks!
Oren
question from:
https://stackoverflow.com/questions/902974/grouping-by-week-month-etc-activerecord 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…