ruby on rails - How to eager load with a condition -
i have classic post has_many relationship on comments. want fetch of approved posts related comments have been approved. have approved scope in place each not sure how enable on comments.
this have far returns comments approved postings. best way without having specify condition on has_many limit use of association other queries.
post.approved.includes(:comments)
your example used in documentation. should use association:
class post < activerecord::base has_many :approved_comments, :class_name => 'comment', :conditions => ['approved = ?', true] end post.includes(:approved_comments)
Comments
Post a Comment