ruby on rails - how to only :include based on a conditional statement -
i'm trying grab posts , comments belong_to post based on conditional:
ie.
# grab posts include comments have been approved. post.all(:include => :comments, :conditions => ['comments.approved = ?', true])
update july 20, 2011 10:11 est
to clarify, i'm trying grab posts , comments of post specific user.
def grab_posts_and_only_comments_from(user) {:include => [:comments], :conditions => ['comments.user_id = ?', user.id]} end
updated july 20, 2011 11:34 est
answer in comment of checked answer.
post.includes(:comments).where("comments.approved = ?", true)
the documentation on feature improved in edgeguides. check out section 12.2 here.
Comments
Post a Comment