Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added counter optimization for AssociationCollection#any? so person.f…
…riends.any? won't actually load the full association if we have the count in a cheaper form [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5676 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Dec 5, 2006
1 parent 5626747 commit 22f095b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Added counter optimization for AssociationCollection#any? so person.friends.any? won't actually load the full association if we have the count in a cheaper form [DHH]

* Subclasses of an abstract class work with single-table inheritance. #5704 [nick+rails@ag.arizona.edu, Ryan Davis, Jeremy Kemper]

* Change fixture_path to a class inheritable accessor allowing test cases to have their own custom set of fixtures. #6672 [zdennis]
Expand Down
Expand Up @@ -119,6 +119,10 @@ def length
def empty?
size.zero?
end

def any?
!empty?
end

def uniq(collection = self)
seen = Set.new
Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/associations_test.rb
Expand Up @@ -508,7 +508,9 @@ def test_finding_using_sql

def test_counting_using_sql
assert_equal 1, Firm.find(:first).clients_using_counter_sql.size
assert Firm.find(:first).clients_using_counter_sql.any?
assert_equal 0, Firm.find(:first).clients_using_zero_counter_sql.size
assert !Firm.find(:first).clients_using_zero_counter_sql.any?
end

def test_counting_non_existant_items_using_sql
Expand Down

0 comments on commit 22f095b

Please sign in to comment.