aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-25 15:38:59 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-25 15:38:59 -0800
commit54a2bf66019d2694ff53f666765faf5bca927c09 (patch)
tree939dd3dabbb5bceb8dfcee1b728d78171b0066bc /activerecord/lib/active_record
parent8fc54a2e814b5c85ccfd798285a366347fd6a4e9 (diff)
downloadrails-54a2bf66019d2694ff53f666765faf5bca927c09.tar.gz
rails-54a2bf66019d2694ff53f666765faf5bca927c09.tar.bz2
rails-54a2bf66019d2694ff53f666765faf5bca927c09.zip
removing limits and offsets from COUNT queries unless both are specified. [#6268 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb14
-rw-r--r--activerecord/lib/active_record/test_case.rb1
2 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index abc4c54109..c1842b1a96 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -204,7 +204,19 @@ module ActiveRecord
relation.select_values = [select_value]
- type_cast_calculated_value(@klass.connection.select_value(relation.to_sql), column_for(column_name), operation)
+ query_builder = relation.arel
+
+ if operation == "count"
+ limit = relation.limit_value
+ offset = relation.offset_value
+
+ unless limit && offset
+ query_builder.limit = nil
+ query_builder.offset = nil
+ end
+ end
+
+ type_cast_calculated_value(@klass.connection.select_value(query_builder.to_sql), column_for(column_name), operation)
end
def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb
index 4e711c4884..29efbbcb8c 100644
--- a/activerecord/lib/active_record/test_case.rb
+++ b/activerecord/lib/active_record/test_case.rb
@@ -26,6 +26,7 @@ module ActiveRecord
def assert_sql(*patterns_to_match)
$queries_executed = []
yield
+ $queries_executed
ensure
failed_patterns = []
patterns_to_match.each do |pattern|