Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure that ORDER BY clauses from default scopes are not included in …

…calculation queries. Fixes #406.
  • Loading branch information...
commit 8f10ccd311e0813114c1aca266c82651ae77f6ca 1 parent b3791da
Jon Leighton jonleighton authored
2  activerecord/lib/active_record/relation/calculations.rb
View
@@ -197,7 +197,7 @@ def operation_over_aggregate_column(column, operation, distinct)
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.
4 activerecord/test/cases/relation_scoping_test.rb
View
@@ -462,4 +462,8 @@ def test_unscoped_with_named_scope_should_not_have_default_scope
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
Please sign in to comment.
Something went wrong with that request. Please try again.