, counter_cache, , , "". - AR , , :
@posts = Post.select("posts.*, COUNT(comments.id) AS count_comments").joins("LEFT OUTER JOIN comments ON posts.id = comments.post_id").group("posts.id").order("count_comments DESC")
@posts.each do |post|
puts "Comments: #{post.count_comments}"
end
count_comments. include, include select. : , , .
SQL , ... :)