diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-20 03:15:22 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-20 03:15:22 +0000 |
commit | 377bdd02b9daba35113299262a98060763925959 (patch) | |
tree | c5db590773c64d334b81a42291d01a6030c1fc84 /activerecord/test | |
parent | 03acf48817d38e8ec4078d50f6ab48a2dfc035b3 (diff) | |
download | rails-377bdd02b9daba35113299262a98060763925959.tar.gz rails-377bdd02b9daba35113299262a98060763925959.tar.bz2 rails-377bdd02b9daba35113299262a98060763925959.zip |
Added :count option to pagination that'll make it possible for the ActiveRecord::Base.count call to using something else than * for the count. Especially important for count queries using DISTINCT #3839 [skaes]. Added :select option to Base.count that'll allow you to select something else than * to be counted on. Especially important for count queries using DISTINCT (closes #3839) [skaes].
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3620 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 475e31028a..4349d92eeb 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1050,19 +1050,39 @@ class BasicsTest < Test::Unit::TestCase def test_count_with_join res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'" - res2 = res + 1 + res2 = nil assert_nothing_raised do res2 = Post.count("posts.#{QUOTED_TYPE} = 'Post'", "LEFT JOIN comments ON posts.id=comments.post_id") end assert_equal res, res2 - res3 = res + 1 + res3 = nil assert_nothing_raised do res3 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'", :joins => "LEFT JOIN comments ON posts.id=comments.post_id") end assert_equal res, res3 + + res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id" + res5 = nil + assert_nothing_raised do + res5 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id", + :joins => "p, comments c", + :select => "p.id") + end + + assert_equal res4, res5 + + res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id" + res7 = nil + assert_nothing_raised do + res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id", + :joins => "p, comments c", + :select => "p.id", + :distinct => true) + end + assert_equal res6, res7 end def test_clear_association_cache_stored |