nikdev
nikdev

Reputation: 61

Ruby On Rails Mongoid Group By

For group by date I used group_by method.

Example: Product.all.group_by {|d| d.created_at } # return Hash 

But kaminari not support Hash. I use Mongoid and me need group by date with page navigation (kaminari). How do it?

Upvotes: 6

Views: 3851

Answers (1)

allenwei
allenwei

Reputation: 4127

Kaminari only support paginate on array for example

Kaminari.paginate_array(an_array).page(1).per(10)

group_by is not mongoid method, it Array's method, it is grouping all data in memory. In order to use mongoid grouping feature, you need use mongodb map/reduce.

If you do need group result in memory, and show it in view, you need manually convert hash to Array

Upvotes: 1

Related Questions