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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -