aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorLauro Caetano <laurocaetano1@gmail.com>2014-04-14 21:35:49 -0300
committerLauro Caetano <laurocaetano1@gmail.com>2014-04-14 22:00:55 -0300
commita9416a407b3e5256a0a3fbe6c6ee5112ca3b6703 (patch)
tree72e7606d9d63a2436313d00e594d686ec6bb62e7 /activerecord/lib/active_record
parent34945e41c24c59268bbde63abfafe20bdc09b775 (diff)
downloadrails-a9416a407b3e5256a0a3fbe6c6ee5112ca3b6703.tar.gz
rails-a9416a407b3e5256a0a3fbe6c6ee5112ca3b6703.tar.bz2
rails-a9416a407b3e5256a0a3fbe6c6ee5112ca3b6703.zip
Make sure the column_name is different from 'all'.
968c581ea34b5236af14805e6a77913b1cb36238 have fixed the EagerLoadTest, but not in the correct way. The problem was when `empty?` or `size` was called on relation. It was triggering `count(:all)`, which was passing `:all` as the column name to `count` on Calculations. On the other hand, the method `calculate` on Calculations was calling `construct_relation_for_association_calculations` instead of `perform_calculation`, because `has_include?` was returning `true` since `column_name` was present. To prevent calling the wrong method to perform the calculation, we have to check if the `column_name` is present and if it is different from `:all` (which is now used to correctly do `count` with `select`). More information here: https://github.com/rails/rails/commit/968c581ea34b5236af14805e6a77913b1cb36238#commitcomment-6006135
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 812e3e800a..514ebc2bfe 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -188,7 +188,7 @@ module ActiveRecord
private
def has_include?(column_name)
- eager_loading? || (includes_values.present? && (column_name || references_eager_loaded_tables?))
+ eager_loading? || (includes_values.present? && ((column_name && column_name != :all) || references_eager_loaded_tables?))
end
def perform_calculation(operation, column_name, options = {})