diff options
author | Mingdong Luo <mdluo@nsmss.com> | 2015-01-31 19:34:56 -0800 |
---|---|---|
committer | Mingdong Luo <mdluo@nsmss.com> | 2015-01-31 19:34:56 -0800 |
commit | 82e710f8471622bd3f3d1640e42ad14f9c9309b9 (patch) | |
tree | 233466527b797fe3ea7c6a7a3673795cea28aebe /activerecord/test/cases/associations | |
parent | 70ac072976c8cc6f013f0df3777e54ccae3f4f8c (diff) | |
parent | 549d171a90135999e3c670f489494b7a39dd6dd7 (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 8 |
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 |