diff options
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 14 |
1 files changed, 13 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: |