From 5bbc461fcbe18b0ab69c459a94cf0b58f5a4e6b9 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 2 Feb 2008 04:28:42 +0000 Subject: Fix calculations on associations with custom :foreign_key. Closes #8117 [kamal, jack] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8778 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index e14700f93b..c8c8d42def 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -213,7 +213,7 @@ module ActiveRecord group_attr = options[:group].to_s association = reflect_on_association(group_attr.to_sym) associated = association && association.macro == :belongs_to # only count belongs_to associations - group_field = (associated ? "#{options[:group]}_id" : options[:group]).to_s + group_field = associated ? association.primary_key_name : group_attr group_alias = column_alias_for(group_field) group_column = column_for group_field sql = construct_calculation_sql(operation, column_name, options.merge(:group_field => group_field, :group_alias => group_alias)) -- cgit v1.2.3