我正在对我的产品进行静力学计算.用户已经执行了很多操作,比如发布 comments .我希望能够向他们展示过go 一个月每周或过go 一年每月发表的 comments 数量.
activerecord有没有办法这样分组?我最好的方法是手动完成这项工作——根据我自己的标准对记录进行迭代求和吗?
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...}
还是有更好的办法?
谢谢