Permalink
Browse files

Merge pull request #14139 from anilmaurya/master

[ci skip] updating active_record/associations to demonstrate where conflict with eager loading.
  • Loading branch information...
2 parents 7707eb9 + be1f2db commit b7b319ec758ae5cd9394e87390813f7bd55e1787 @senny senny committed Apr 28, 2014
Showing with 6 additions and 0 deletions.
  1. +6 −0 activerecord/lib/active_record/associations.rb
@@ -773,6 +773,12 @@ def association_instance_set(name, association)
# like this can have unintended consequences.
# In the above example posts with no approved comments are not returned at all, because
# the conditions apply to the SQL statement as a whole and not just to the association.
+ #
+ # If you want to load all posts (including posts with no approved comments) then write
+ # your own LEFT OUTER JOIN query using ON
+ #
+ # Post.joins('LEFT OUTER JOIN comments ON comments.post_id = posts.id AND comments.approved = true')
+ #
# You must disambiguate column references for this fallback to happen, for example
# <tt>order: "author.name DESC"</tt> will work but <tt>order: "name DESC"</tt> will not.
#

0 comments on commit b7b319e

Please sign in to comment.