0

Currently, we are trying to determine a users ranking.

We do this by a number of joins and what inevitably comes down to:

.group("users.id").order(SUM(some_joined_value) DESC, SUM(some_other_joined_value) DESC).pluck("users.id")

Now that this is in a sorted array, I can determine what ranking they are by using Array#index on the id. The problem is that this is ~ 15,000 records, is there a way to determine the row number in the result set without loading all of the data into an array? I'm using MySQL as my database adapter.

Senjai
  • 1,811
  • 3
  • 20
  • 40
  • You probably have to go all MySQL here, how about something like this: http://stackoverflow.com/a/2520377/637094 – Leonel Galán Mar 17 '14 at 17:58
  • Yes you could use a partition style Query but why are you opposed to using `each_with_index` this method will do what you want in a ruby way since you are already building an array in your code. – engineersmnky Mar 17 '14 at 18:01
  • This could probably be done with ActiveRecord alone. Can you post your models and describe how their rank is calculated? – opticon Mar 17 '14 at 18:50

0 Answers0