Group and count in Rails

后端 未结 7 1930
傲寒
傲寒 2021-02-01 12:06

I know I\'ve seen this before but I can\'t find anything now. I want to group a query by a certain column and be able to display how many are in each group. I got the first part

相关标签:
7条回答
  • 2021-02-01 12:58

    After this commit:

    https://github.com/rails/rails/commit/a1c05dd8b9bd3623289d3aa73dda2943d620cc34

    there's a new way to do the same thing:

    @project.line_items.count(:group => LineItem.arel_table[:device_id])
    
    0 讨论(0)
提交回复
热议问题