Filter by count of children using Rails 3
问题 I'd like to select posts that have one or more comments using Rails 3 and a single query. I'm trying something like this: Post.includes(:comments).where('count(comments.id)>0') However I get this error: ActiveRecord::StatementInvalid: PGError: ERROR: aggregates not allowed in WHERE clause I've googled this and similar approaches, group by, etc with no luck. Any help will be appreciated. 回答1: I'm sure you may have figured this out by now, but I believe what you're looking for is the having(