diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-08 23:31:16 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-08 23:31:16 +0100 |
commit | 8f10ccd311e0813114c1aca266c82651ae77f6ca (patch) | |
tree | d859336b050c400eb0b2d211091f925ce7d026e0 /activerecord | |
parent | b3791da0318eb68f14a2d8d7658cc882784e6f6a (diff) | |
download | rails-8f10ccd311e0813114c1aca266c82651ae77f6ca.tar.gz rails-8f10ccd311e0813114c1aca266c82651ae77f6ca.tar.bz2 rails-8f10ccd311e0813114c1aca266c82651ae77f6ca.zip |
Ensure that ORDER BY clauses from default scopes are not included in calculation queries. Fixes #406.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation_scoping_test.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 869eebfa34..a8a52867ce 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -197,7 +197,7 @@ module ActiveRecord def execute_simple_calculation(operation, column_name, distinct) #:nodoc: # Postgresql doesn't like ORDER BY when there are no GROUP BY - relation = except(:order) + relation = reorder(nil) if operation == "count" && (relation.limit_value || relation.offset_value) # Shortcut when limit is zero. diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 864b3d4846..c215602567 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -462,4 +462,8 @@ class DefaultScopingTest < ActiveRecord::TestCase assert DeveloperCalledJamis.unscoped.poor.include?(developers(:david).becomes(DeveloperCalledJamis)) assert_equal 10, DeveloperCalledJamis.unscoped.poor.length end + + def test_default_scope_order_ignored_by_aggregations + assert_equal DeveloperOrderedBySalary.all.count, DeveloperOrderedBySalary.count + end end |