提交 5a0d8045 编写于 作者: R Rafael Mendonça França

Merge pull request #14756 from laurocaetano/fix-count-on-association-relation

Fix count on association relation (calls to empty and size).
......@@ -9,14 +9,6 @@ def proxy_association
@association
end
def size
@association.size
end
def empty?
@association.empty?
end
def ==(other)
other == to_a
end
......
......@@ -188,7 +188,7 @@ def ids
private
def has_include?(column_name)
eager_loading? || (includes_values.present? && (column_name || references_eager_loaded_tables?))
eager_loading? || (includes_values.present? && ((column_name && column_name != :all) || references_eager_loaded_tables?))
end
def perform_calculation(operation, column_name, options = {})
......
......@@ -864,6 +864,17 @@ def test_count
assert_equal 9, posts.where(:comments_count => 0).count
end
def test_count_on_association_relation
author = Author.last
another_author = Author.first
posts = Post.where(author_id: author.id)
assert_equal author.posts.where(author_id: author.id).size, posts.count
assert_equal 0, author.posts.where(author_id: another_author.id).size
assert author.posts.where(author_id: another_author.id).empty?
end
def test_count_with_distinct
posts = Post.all
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册