Currently, my code looks like this:
Author.joins(:books).group("authors.id").order("count (authors.id) desc")
Which does an order by how many books the author has written. However, books is a very large database table. So, to speed things up without having to use a .joins, how would one write something that would work with a .pluck statement to get the books.id, such as:
Author.order("count (id: Book.uniq.pluck(:author_id)) desc")
(this code brings up a syntax error) Is this mainly an issue of how it has been written and formatted? Or, is there a better way to refactor this type of statement?