Last Updated: June 14, 2017
·
156
· lazybios

order by association count

Author.joins(:articles).select("count(articles.id) as article_count").group("authors.id").order("article_count")

add index to counter_cache column and order by it.

scope :hot, oder(:articles_count)