mysql - Using :include and :conditions creates big queries? -


i want fetch posts commented specifc user eager loading of creator,editor,comments , forum.

post.rb

named_scope :list_of_post {|user_id|   {     :include => [:creator,:editor,:comments,:forum],     :conditions => ["comments.user_id = ?",user_id]   } }  

but named scope creates big query instead of small in queries creator,editor,comments , forum.

this happening because of using :include , :conditions together.

any solutions returns in queries each instead of 1 big query.

i assume you're using rails 2 instead of scope :

post.find(:conditions => {:id => user.comments.map(:post_id)}, :include => [...]) 

when migrate rails 3, @ squeel , ransack. requests easier.


Comments

Popular posts from this blog

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -