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:
An alternative approach to the one of Zubin:
Post.select('posts.*, count(comments.id) `comments_count`').joins(:comments).group('posts.id')