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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -