I'll use the generic blog example.
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
When querying Post, how do you access its associations (i.e. :comments)?
This should be the easiest thing in the world, but I haven't found any documentation on it. Even http://edgeguides.rubyonrails.org/3_0_release_notes.html#query-interface and http://m.onkey.org/2010/1/22/active-record-query-interface were unhelpful, basically saying "Now there are methods like joins and includes to do the same thing as SQL statements." yeah thanks.
So here are very straightforward things I want to do, which do not work, but should be obvious what I'm trying to accomplish:
Post.where(:comments.count >= 10)
Post.where(:comments.author_id == current_user.id)
Post.order(:comments.count)
How can we do these without resorting to ruby code that reeks of SQL (thus defeating the purpose of Active Record)? Thanks :)