From 74c2961bd864f633c79c03e62c2cb142642201c5 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 28 Jan 2015 16:01:12 -0700 Subject: Don't error when grouped calculations return 0 records Fixes #18717 --- activerecord/lib/active_record/relation/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/relation') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 83745bc169..c3c4d7f1ce 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -304,7 +304,7 @@ module ActiveRecord if association key_ids = calculated_data.collect { |row| row[group_aliases.first] } - key_records = association.klass.base_class.find(key_ids) + key_records = association.klass.base_class.where(association.klass.base_class.primary_key => key_ids) key_records = Hash[key_records.map { |r| [r.id, r] }] end -- cgit v1.2.3