mysql - get count of has_many association in rails query -


i have 2 model. post , `comment'.

post has_may comments.

query: want max count of comments in post.

this should done rail query.

@post = post.   joins(:comments).   select('posts.*, count(comments.id) comment_count').   group("posts.id").   first 

Comments