Rails 3 Query Interface: using associated models?

If you set up a counter_cache on Post for the comments you can see directly how many comments it has without having to query, this makes it easier and faster.

If you set up a counter_cache on Post for the comments you can see directly how many comments it has without having to query, this makes it easier and faster. This would take care of the first and last question you posed. You can then query them like this, Post.

Where(:comments_count >= 10) Post. Order(:comments_count) But you are better off setting up scopes for that. I'm not sure what you want to do with the second question, do you want to show all posts where the current user has commented on?

As for your last question, yes that's right. – Arcolye Oct 22 '10 at 9:28.

Post. Where(:comments. Count >= 10) Post.

Find(:all). Select{|p| p.comments. Count >= 10) Post.

Where(:comments. Author_id == current_user. Id) Post.

Find(:all). Select{|p| p.comments. Select{|c| c.

Author_id == current_user. Id } } Post. Order(:comments.

Count) Yikes, this one beats me. My two posts are kinda heavy on the SQL. I know people do it more elgantly with a Post.

Find(:all, :conditions => blah blah blah.. But I'm not sure how to put that. Sorry.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions