diff options
author | Aaron Wortham <wortham.aaron@gmail.com> | 2017-08-09 10:24:13 -0700 |
---|---|---|
committer | Aaron Wortham <wortham.aaron@gmail.com> | 2017-08-14 13:22:59 -0700 |
commit | 566f1fd068711dfe557bef63406f8dd6d41d473d (patch) | |
tree | b705a048d38792af7027821f4046280cc4c62185 /activerecord/lib/active_record | |
parent | 3cfadd5fa2306ec1f382343220805546e1444cd8 (diff) | |
download | rails-566f1fd068711dfe557bef63406f8dd6d41d473d.tar.gz rails-566f1fd068711dfe557bef63406f8dd6d41d473d.tar.bz2 rails-566f1fd068711dfe557bef63406f8dd6d41d473d.zip |
Ensure sum honors distinct on has_many through
When using a has_many through relation and then summing an attribute
the distinct was not being used. This will ensure that when summing
an attribute, the number is only used once when distinct has been used.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index d3b5be6bce..42d43224fa 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -259,6 +259,9 @@ module ActiveRecord column = aggregate_column(column_name) select_value = operation_over_aggregate_column(column, operation, distinct) + if operation == "sum" && distinct + select_value.distinct = true + end column_alias = select_value.alias column_alias ||= @klass.connection.column_name_for_operation(operation, select_value) |