我在我的产品中做了一些静力学计算.用户已经执行了许多操作,比方说发布了评论.我希望能够向他们展示他们在过去一个月或过去一年中每个月每周发布的评论数量.
有没有办法用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...}
Run Code Online (Sandbox Code Playgroud)
或者有更好的方法吗?
谢谢!奥伦