I have three models:
- Book [belongs_to :author]
- Author [belongs_to :publisher, has_many :books]
- Publisher [has_many :authors]
I want to know how many Books have every Publisher, grouped by Publisher and ordered by Publishers with most Books. I need to get a list with a single query, where I can get something like:
- Publisher ABC: 3800 books
- Publisher XYZ: 1922 books
- Publisher JKL: 192 books
- and so on
Books belongs to Author but not to Publisher directly —complicated to explain why. Is there a easy way to achieve this?