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

objective c - Can't build GCM with Protobuf in Xcode -

ember.js - EmberJS Model find not up-to-date with underlying store -

javascript - jQuery iScroll clickable list elements while retaining scroll? -