cakephp find all posts that have comments

MicroBoy

New Member
I created a simple blog that has posts and comments. I want to find all the posts that have at least one comment and also find all the posts with no comments. Is there a cakephp way to do this? I.E. maybe something like\[code\]$this->Post->find('all', ???);\[/code\]I ended up writing my own query, the example below finds all the posts with at least 1 comment\[code\]SELECT * FROM ( select posts.*, count(comments.id) as comment_count from posts left join comments on posts.id = comments.post_id group by posts.id ) as T WHERE comment_count != 0\[/code\]but there seems like there would be a better way to do this.Note: a Post hasMany Comment and Comment belongsTo Post
 
Back
Top