提交 31d8169e 编写于 作者: R Rick Olson

Fixed that loading including associations returns all results if Load IDs For...

Fixed that loading including associations returns all results if Load IDs For Limited Eager Loading returns none (closes #4528) [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4179 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 42d8548e
*SVN*
* Fixed that loading including associations returns all results if Load IDs For Limited Eager Loading returns none (closes #4528) [Rick]
* Fixed HasManyAssociation#find bugs when :finder_sql is set #4600 [lagroue@free.fr]
* Allow AR::Base#respond_to? to behave when @attributes is nil [zenspider]
......
......@@ -962,14 +962,20 @@ def association_constructor_method(constructor, reflection, association_proxy_cl
end
def count_with_associations(options = {})
join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins])
return count_by_sql(construct_counter_sql_with_included_associations(options, join_dependency))
catch :invalid_query do
join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins])
return count_by_sql(construct_counter_sql_with_included_associations(options, join_dependency))
end
0
end
def find_with_associations(options = {})
join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins])
rows = select_all_rows(options, join_dependency)
return join_dependency.instantiate(rows)
catch :invalid_query do
join_dependency = JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins])
rows = select_all_rows(options, join_dependency)
return join_dependency.instantiate(rows)
end
[]
end
def configure_dependency_for_has_many(reflection)
......@@ -1151,6 +1157,8 @@ def construct_finder_sql_with_included_associations(options, join_dependency)
def add_limited_ids_condition!(sql, options, join_dependency)
unless (id_list = select_limited_ids_list(options, join_dependency)).empty?
sql << "#{condition_word(sql)} #{table_name}.#{primary_key} IN (#{id_list}) "
else
throw :invalid_query
end
end
......
......@@ -138,6 +138,16 @@ def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
assert_equal count, posts.size
end
def test_eager_with_has_many_and_limit_ond_high_offset
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ])
assert_equal 0, posts.size
end
def test_count_eager_with_has_many_and_limit_ond_high_offset
posts = Post.count(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ])
assert_equal 0, posts
end
def test_eager_with_has_many_and_limit_with_no_results
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'")
assert_equal 0, posts.size
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册