diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-09 15:18:59 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-09 16:06:04 +0900 |
commit | c5ab6e51a7b9ee05a2d262a72c7130b9c1d1b0ce (patch) | |
tree | 2d8ac7f3e896045390ec35455cf61a0bc25275f5 /activerecord/test | |
parent | b1e7bb9ed7ddbb29fd788dee1c3f2ba2626bd7ac (diff) | |
download | rails-c5ab6e51a7b9ee05a2d262a72c7130b9c1d1b0ce.tar.gz rails-c5ab6e51a7b9ee05a2d262a72c7130b9c1d1b0ce.tar.bz2 rails-c5ab6e51a7b9ee05a2d262a72c7130b9c1d1b0ce.zip |
Joined tables in association scope doesn't use the same aliases with the parent relation's aliases
Building association scope in join dependency should respect the parent
relation's aliases to avoid using the same alias name more than once.
Fixes #30681.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/author.rb | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 521b388cee..c6a4ac356f 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -1250,6 +1250,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase TenantMembership.current_member = nil end + def test_has_many_trough_with_scope_that_has_joined_same_table_with_parent_relation + assert_equal authors(:david), Author.joins(:comments_for_first_author).take + end + def test_has_many_through_with_unscope_should_affect_to_through_scope assert_equal [comments(:eager_other_comment1)], authors(:mary).unordered_comments end diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 3371fcbfcc..e9eba9be2e 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -22,6 +22,7 @@ class Author < ActiveRecord::Base has_many :comments_containing_the_letter_e, through: :posts, source: :comments has_many :comments_with_order_and_conditions, -> { order("comments.body").where("comments.body like 'Thank%'") }, through: :posts, source: :comments has_many :comments_with_include, -> { includes(:post).where(posts: { type: "Post" }) }, through: :posts, source: :comments + has_many :comments_for_first_author, -> { for_first_author }, through: :posts, source: :comments has_many :first_posts has_many :comments_on_first_posts, -> { order("posts.id desc, comments.id asc") }, through: :first_posts, source: :comments |