Order Players on the SUM of their association model

前端 未结 1 935
后悔当初
后悔当初 2021-01-06 01:03

I have a database with 6500 players and each player has an average of 15 game results.

Use case

I want to generat

相关标签:
1条回答
  • 2021-01-06 01:38

    You should be able to use something like this:

    class Player
     scope :order_by_prize, joins(:results).select('name, sum(results.prize) as total_prize').order('total_prize desc')  
    

    Refer rails api - active record querying for details.

    0 讨论(0)
提交回复
热议问题