aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-11-10 22:22:55 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-11-10 22:22:55 +0900
commitdf49896a1e67feea56062639c3cf51e8e0b12a51 (patch)
tree719511d0ac433a8a4c2cc1dc9a50eab7dfac9a3e /activerecord/test/cases/relations_test.rb
parenta7ef60d5207d3b227d6b7dfe21e453d3548cdefa (diff)
downloadrails-df49896a1e67feea56062639c3cf51e8e0b12a51.tar.gz
rails-df49896a1e67feea56062639c3cf51e8e0b12a51.tar.bz2
rails-df49896a1e67feea56062639c3cf51e8e0b12a51.zip
Ensure `apply_join_dependency` for subqueries in `from` and `where`
Fixes #21577.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 844be0d0bf..e44533cf60 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -195,6 +195,18 @@ class RelationTest < ActiveRecord::TestCase
assert_equal(relation.map(&:post_count).sort, subquery.values.sort)
end
+ def test_finding_with_subquery_with_eager_loading_in_from
+ relation = Comment.includes(:post).where("posts.type": "Post")
+ assert_equal relation.to_a, Comment.select("*").from(relation).to_a
+ assert_equal relation.to_a, Comment.select("subquery.*").from(relation).to_a
+ assert_equal relation.to_a, Comment.select("a.*").from(relation, :a).to_a
+ end
+
+ def test_finding_with_subquery_with_eager_loading_in_where
+ relation = Comment.includes(:post).where("posts.type": "Post")
+ assert_equal relation.to_a, Comment.where(id: relation).to_a
+ end
+
def test_finding_with_conditions
assert_equal ["David"], Author.where(name: "David").map(&:name)
assert_equal ["Mary"], Author.where(["name = ?", "Mary"]).map(&:name)