I am running Ruby on Rails 3.1. I read the following articles and documentations about eager loading and I would like to find a right way to do things:

  1. Eager Loading Associations [Official documentation]
  2. ActiveRecord::Associations::ClassMethods (see the section "Eager loading of associations") [Official documentation]
  3. Eager loading [Blog article]

The #2 says:

Note that using conditions like Post.includes([:author, :comments]).where(['comments.approved = ?', true]).all can have unintended consequences.

The #3 says that those unintended consequences are (note: examples are pretty the same so I quote the exact text of the blog article but you have to keep in mind the workaround, not the specific implementation):

This query, since it would use a LEFT JOIN, would also discard all posts without a comment with the word “first” on any of it’s comments.

That is, if there are non "associated" objects, the "main associated" object will not be loaded. This is what happens when I try to use eager loading by adding some condition like .where(:category_relationships => {:user_id => @current_user.id}) in a my previous question, but I do not want that to happen.

So (defeatist because I probably can not use the eager loading in my case where condition can not be set in the has_many

Edit
Report