Changeset 8779
- Timestamp:
- 02/02/08 04:56:11 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2-0-stable/activerecord/lib/active_record/calculations.rb
r8381 r8779 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 branches/2-0-stable/activerecord/test/calculations_test.rb
r7192 r8779 160 160 end 161 161 end 162 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)] 169 end 170 163 171 def test_should_not_modify_options_when_using_includes 164 172 options = {:conditions => 'companies.id > 1', :include => :firm}