-1

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.

Vinay
  • 324
  • 1
  • 3
  • 15

1 Answers1

0
@post = Post.
  joins(:comments).
  select('posts.*, count(comments.id) as comment_count').
  group("posts.id").
  first
antiqe
  • 1,125
  • 8
  • 17
Vrushali Pawar
  • 3,753
  • 1
  • 13
  • 22
  • I am looking for a query from which I can get the post which have max number of comments among other posts. Now do you understand? – Vinay Jun 04 '15 at 11:31