This is related to a question a year and change ago.
I put up an example of the question that should work out of the box, provided you have sqlite3 available: https:
I have set up a small gem that adds an includes_count method to ActiveRecord, that uses a SELECT COUNT to fetch the number of records in an association, without resorting to a JOIN which might be expensive (depending on the case).
includes_count
See https://github.com/manastech/includes-count
Hope it helps!