提交 1a7567d2 编写于 作者: B Boris Staal

Eager loading made to use relation's in_clause_length instead of host's one (fixes #8474)

上级 42b555dc
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* Eager loading made to use relation's in_clause_length instead of host's one.
Fix #8474
*Boris Staal*
* Explicit multipart messages no longer set the order of the MIME parts. * Explicit multipart messages no longer set the order of the MIME parts.
*Nate Berkopec* *Nate Berkopec*
......
...@@ -76,7 +76,7 @@ def associated_records_by_owner ...@@ -76,7 +76,7 @@ def associated_records_by_owner
else else
# Some databases impose a limit on the number of ids in a list (in Oracle it's 1000) # Some databases impose a limit on the number of ids in a list (in Oracle it's 1000)
# Make several smaller queries if necessary or make one query if the adapter supports it # Make several smaller queries if necessary or make one query if the adapter supports it
sliced = owner_keys.each_slice(model.connection.in_clause_length || owner_keys.size) sliced = owner_keys.each_slice(klass.connection.in_clause_length || owner_keys.size)
records = sliced.map { |slice| records_for(slice).to_a }.flatten records = sliced.map { |slice| records_for(slice).to_a }.flatten
end end
......
...@@ -93,31 +93,31 @@ def test_duplicate_middle_objects ...@@ -93,31 +93,31 @@ def test_duplicate_middle_objects
end end
def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5) Comment.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.all.merge!(:includes=>:comments).to_a posts = Post.all.merge!(:includes=>:comments).to_a
assert_equal 11, posts.size assert_equal 11, posts.size
end end
def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil) Comment.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.all.merge!(:includes=>:comments).to_a posts = Post.all.merge!(:includes=>:comments).to_a
assert_equal 11, posts.size assert_equal 11, posts.size
end end
def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5) Comment.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.all.merge!(:includes=>:categories).to_a posts = Post.all.merge!(:includes=>:categories).to_a
assert_equal 11, posts.size assert_equal 11, posts.size
end end
def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil) Comment.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.all.merge!(:includes=>:categories).to_a posts = Post.all.merge!(:includes=>:categories).to_a
assert_equal 11, posts.size assert_equal 11, posts.size
end end
def test_load_associated_records_in_one_query_when_adapter_has_no_limit def test_load_associated_records_in_one_query_when_adapter_has_no_limit
Post.connection.expects(:in_clause_length).at_least_once.returns(nil) Comment.connection.expects(:in_clause_length).at_least_once.returns(nil)
post = posts(:welcome) post = posts(:welcome)
assert_queries(2) do assert_queries(2) do
...@@ -126,7 +126,7 @@ def test_load_associated_records_in_one_query_when_adapter_has_no_limit ...@@ -126,7 +126,7 @@ def test_load_associated_records_in_one_query_when_adapter_has_no_limit
end end
def test_load_associated_records_in_several_queries_when_many_ids_passed def test_load_associated_records_in_several_queries_when_many_ids_passed
Post.connection.expects(:in_clause_length).at_least_once.returns(1) Comment.connection.expects(:in_clause_length).at_least_once.returns(1)
post1, post2 = posts(:welcome), posts(:thinking) post1, post2 = posts(:welcome), posts(:thinking)
assert_queries(3) do assert_queries(3) do
...@@ -135,7 +135,7 @@ def test_load_associated_records_in_several_queries_when_many_ids_passed ...@@ -135,7 +135,7 @@ def test_load_associated_records_in_several_queries_when_many_ids_passed
end end
def test_load_associated_records_in_one_query_when_a_few_ids_passed def test_load_associated_records_in_one_query_when_a_few_ids_passed
Post.connection.expects(:in_clause_length).at_least_once.returns(3) Comment.connection.expects(:in_clause_length).at_least_once.returns(3)
post = posts(:welcome) post = posts(:welcome)
assert_queries(2) do assert_queries(2) do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册