diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-31 11:48:35 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-31 11:48:35 -0200 |
commit | b953b2fc464a31dfd040de126030ac05e18f6e4c (patch) | |
tree | 2935b12ef456f162c27bdc3ad001167b50836bd7 /activerecord | |
parent | f3a8be3b8be496cd5de14e9c29de3748432d5da0 (diff) | |
parent | 8e1f26c66c5cd1ceb23baca5fb48440a8c9a06c1 (diff) | |
download | rails-b953b2fc464a31dfd040de126030ac05e18f6e4c.tar.gz rails-b953b2fc464a31dfd040de126030ac05e18f6e4c.tar.bz2 rails-b953b2fc464a31dfd040de126030ac05e18f6e4c.zip |
Merge pull request #13525 from huoxito/make-outer-joins-on-proper-parent
Make outer joins on proper parent
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 9506960be3..295dccf34e 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -114,7 +114,7 @@ module ActiveRecord walk join_root, oj.join_root else oj.join_root.children.flat_map { |child| - make_outer_joins join_root, child + make_outer_joins oj.join_root, child } end } diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 70d113fb39..c4e7ba78c1 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -207,6 +207,17 @@ module ActiveRecord assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count.length end + def test_relation_merging_with_joins_as_join_dependency_pick_proper_parent + post = Post.create!(title: "haha", body: "huhu") + comment = post.comments.create!(body: "hu") + 3.times { comment.ratings.create! } + + relation = Post.joins Associations::JoinDependency.new(Post, :comments, []) + relation = relation.joins Associations::JoinDependency.new(Comment, :ratings, []) + + assert_equal 3, relation.pluck(:id).select { |id| id == post.id }.count + end + def test_respond_to_for_non_selected_element post = Post.select(:title).first assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception" @@ -221,6 +232,5 @@ module ActiveRecord posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings) assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count.length end - end end |