aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/eager_test.rb
diff options
context:
space:
mode:
authorMingdong Luo <mdluo@nsmss.com>2015-01-31 19:34:56 -0800
committerMingdong Luo <mdluo@nsmss.com>2015-01-31 19:34:56 -0800
commit82e710f8471622bd3f3d1640e42ad14f9c9309b9 (patch)
tree233466527b797fe3ea7c6a7a3673795cea28aebe /activerecord/test/cases/associations/eager_test.rb
parent70ac072976c8cc6f013f0df3777e54ccae3f4f8c (diff)
parent549d171a90135999e3c670f489494b7a39dd6dd7 (diff)
downloadrails-82e710f8471622bd3f3d1640e42ad14f9c9309b9.tar.gz
rails-82e710f8471622bd3f3d1640e42ad14f9c9309b9.tar.bz2
rails-82e710f8471622bd3f3d1640e42ad14f9c9309b9.zip
Merge pull request #1 from mdluo/pr/18316
Fix n+1 query problem when eager loading nil associations (fixes #18312)
Diffstat (limited to 'activerecord/test/cases/associations/eager_test.rb')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 371635d20a..7d8b933992 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -77,9 +77,17 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_has_many_through_with_order
authors = Author.includes(:favorite_authors).to_a
+ assert authors.count > 0
assert_no_queries { authors.map(&:favorite_authors) }
end
+ def test_eager_loaded_has_one_association_with_references_does_not_run_additional_queries
+ Post.update_all(author_id: nil)
+ authors = Author.includes(:post).references(:post).to_a
+ assert authors.count > 0
+ assert_no_queries { authors.map(&:post) }
+ end
+
def test_with_two_tables_in_from_without_getting_double_quoted
posts = Post.select("posts.*").from("authors, posts").eager_load(:comments).where("posts.author_id = authors.id").order("posts.id").to_a
assert_equal 2, posts.first.comments.size