I have a two model
. Post
and `Comment'.
Post
has_may comments
.
Query: I want to get the max count of comments in which post.
This should be done by rail
query.
I have a two model
. Post
and `Comment'.
Post
has_may comments
.
Query: I want to get the max count of comments in which post.
This should be done by rail
query.
@post = Post.
joins(:comments).
select('posts.*, count(comments.id) as comment_count').
group("posts.id").
first