diff options
author | Sammy Larbi <sam@codeodor.com> | 2015-01-03 13:30:30 -0600 |
---|---|---|
committer | Sammy Larbi <sam@codeodor.com> | 2015-01-03 13:31:54 -0600 |
commit | c840b18ac31a852d99ff760229f2c087b6961727 (patch) | |
tree | 5be634d408733d781de4fca2b77870b6fed3e026 /activerecord/test/cases/associations | |
parent | 02e72a49d1c99084fef2c78c3a194e03b879099d (diff) | |
download | rails-c840b18ac31a852d99ff760229f2c087b6961727.tar.gz rails-c840b18ac31a852d99ff760229f2c087b6961727.tar.bz2 rails-c840b18ac31a852d99ff760229f2c087b6961727.zip |
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 fdb437d11d..1d00177405 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 |