Skip to content

Instantly share code, notes, and snippets.

@gringocl
Created January 29, 2014 18:50
Show Gist options
  • Save gringocl/8694367 to your computer and use it in GitHub Desktop.
Save gringocl/8694367 to your computer and use it in GitHub Desktop.
ActiveRecord query method chains
User.all.includes(:questions).map(&:question_ids).flatten.group_by { |n| n }.map { |k,v| [ k, v.size ] }.sort_by { |a| a.last }.each { |a| max = a.last if a.last > max }.select { |e| e.last == max }
User.all.map(&:question_ids).flatten.group_by { |n| n }.map { |k,v| [ k, v.size ] }.sort_by { |a| a.last }.each { |a| max = a.last if a.last > max }.select { |e| e.last == max }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment