views:

16

answers:

1

I think the problem is trivial.I have two models: User and Betting. User has_many :bettings

Betting belongs_to :user

I just want to get the users ordered by who made more bettings.

Sorry, for my english

Thanks in advance Francesco

A: 

Are you on Rails2 or Rails3?

On Rails3, you can use the Ruby sort method and something like:

User.includes(:bettings).sort{|x,y| x.bettings.size <=> y.bettings.size}

Of course, in this case the sorting occurs after the SQL request, which is not optimum if you have large tables… I'm trying to figure how to do it at the SQL level with no answer yet…

Yannis
I tried this code, but I think there is a better solution,Thanks anyway
fra