diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-27 23:26:14 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-27 23:26:14 +0900 |
commit | 99df469ddc3dc4be611f4a17f76d14af9ab01bbd (patch) | |
tree | 4916978063ef89b0ff6e3a63f283335d0969a2c4 /activerecord/test | |
parent | dbcaf9d157c9303d617a200e8c4b0832eb8af749 (diff) | |
parent | 20ede2e2e6e28cf26da4d056cd7638b27d48ed57 (diff) | |
download | rails-99df469ddc3dc4be611f4a17f76d14af9ab01bbd.tar.gz rails-99df469ddc3dc4be611f4a17f76d14af9ab01bbd.tar.bz2 rails-99df469ddc3dc4be611f4a17f76d14af9ab01bbd.zip |
Merge pull request #36120 from kamipo/should_maintain_join_type
Fix merging left_joins to maintain its own `join_type` context
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/left_outer_join_association_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/left_outer_join_association_test.rb b/activerecord/test/cases/associations/left_outer_join_association_test.rb index 0a8863c35d..d44c6407f5 100644 --- a/activerecord/test/cases/associations/left_outer_join_association_test.rb +++ b/activerecord/test/cases/associations/left_outer_join_association_test.rb @@ -32,6 +32,10 @@ class LeftOuterJoinAssociationTest < ActiveRecord::TestCase assert_equal 17, Post.left_outer_joins(:comments).count end + def test_merging_left_joins_should_be_left_joins + assert_equal 5, Author.left_joins(:posts).merge(Post.no_comments).count + end + def test_left_joins_aliases_left_outer_joins assert_equal Post.left_outer_joins(:comments).to_sql, Post.left_joins(:comments).to_sql end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 090b576a5d..50c0dddcf2 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -43,6 +43,7 @@ class Post < ActiveRecord::Base has_one :first_comment, -> { order("id ASC") }, class_name: "Comment" has_one :last_comment, -> { order("id desc") }, class_name: "Comment" + scope :no_comments, -> { left_joins(:comments).where(comments: { id: nil }) } scope :with_special_comments, -> { joins(:comments).where(comments: { type: "SpecialComment" }) } scope :with_very_special_comments, -> { joins(:comments).where(comments: { type: "VerySpecialComment" }) } scope :with_post, ->(post_id) { joins(:comments).where(comments: { post_id: post_id }) } |