diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-02 04:28:42 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-02 04:28:42 +0000 |
commit | 5bbc461fcbe18b0ab69c459a94cf0b58f5a4e6b9 (patch) | |
tree | 8fa372dcec9d6ae9822038cb590fbce4b92a6f4d /activerecord/lib | |
parent | 6d8534acc032ab3a1ecbb88e9a0ce09d18734071 (diff) | |
download | rails-5bbc461fcbe18b0ab69c459a94cf0b58f5a4e6b9.tar.gz rails-5bbc461fcbe18b0ab69c459a94cf0b58f5a4e6b9.tar.bz2 rails-5bbc461fcbe18b0ab69c459a94cf0b58f5a4e6b9.zip |
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
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/calculations.rb | 2 |
1 files changed, 1 insertions, 1 deletions
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)) |