From 5757fe476a126d4f7de2791da5af0e6aeef0d1e6 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 3 May 2014 17:16:53 +0200 Subject: docs, restructure newly added part to `includes`. [ci skip] This is a follow up to #14139. /cc @carlosantoniodasilva --- activerecord/lib/active_record/associations.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 265bad7bc2..ac1479ad8f 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -774,16 +774,15 @@ module ActiveRecord # 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. # + # You must disambiguate column references for this fallback to happen, for example + # order: "author.name DESC" will work but order: "name DESC" will not. + # # 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 - # order: "author.name DESC" will work but order: "name DESC" will not. + # Post.joins("LEFT OUTER JOIN comments ON comments.post_id = posts.id AND comments.approved = '1'") # - # If you do want eager load only some members of an association it is usually more natural - # to include an association which has conditions defined on it: + # In this case it is usually more natural to include an association which has conditions defined on it: # # class Post < ActiveRecord::Base # has_many :approved_comments, -> { where approved: true }, class_name: 'Comment' -- cgit v1.2.3