Rails ActiveRecord: Select Posts WITHOUT comments

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2010-06-06T08:53:00Z Indexed on 2010/06/06 9:02 UTC
Read the original article Hit count: 668

Filed under:
|
|

I have a a Comments table and a Posts table, where a Post has many comments and a comment belongs to a post (i.e. it has a post_id in the table).

How can I efficiently select the last ten Posts that DO NOT have comments. I can't seem to accomplish this without first selecting all the posts and checking each for a 0 comment count.

Thanks in advance for any help.

-Nathan

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord