Changeset 8778
- Timestamp:
- 02/02/08 04:28:42 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/calculations.rb
r8494 r8778 214 214 association = reflect_on_association(group_attr.to_sym) 215 215 associated = association && association.macro == :belongs_to # only count belongs_to associations 216 group_field = (associated ? "#{options[:group]}_id" : options[:group]).to_s216 group_field = associated ? association.primary_key_name : group_attr 217 217 group_alias = column_alias_for(group_field) 218 218 group_column = column_for group_field trunk/activerecord/test/cases/calculations_test.rb
r8681 r8778 159 159 assert_equal 1, c.first.last 160 160 end 161 end 162 163 def test_should_calculate_grouped_association_with_foreign_key_option 164 Account.belongs_to :another_firm, :class_name => 'Firm', :foreign_key => 'firm_id' 165 c = Account.count(:all, :group => :another_firm) 166 assert_equal 1, c[companies(:first_firm)] 167 assert_equal 2, c[companies(:rails_core)] 168 assert_equal 1, c[companies(:first_client)] 161 169 end 162 170