I have two models:
Novel has_many :pages
Page belongs_to :novel
I want to list popular Novels according to page count. Essentially, I want Novel models loaded from the outcome of this query:
select p.novel_id, count(*) as count
from pages p
GROUP BY p.novel_id
ORDER BY count DESC
I'm sure there's some cute way to do it in Rails 2.3 using named_scope, but I can't quite get it to work. Plus, if it does work, is it going to be dog slow?
I've considered keeping page_count on Novel, but that seems like a violation of something (convention, normalization, my soul).