Changeset 6919
- Timestamp:
- 06/01/07 03:26:51 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/calculations.rb (modified) (1 diff)
- trunk/activerecord/test/calculations_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6909 r6919 1 1 *SVN* 2 3 * Calculations support non-numeric foreign keys. #8154 [kamal] 2 4 3 5 * with_scope is protected. #8524 [Josh Peek] trunk/activerecord/lib/active_record/calculations.rb
r6904 r6919 236 236 237 237 calculated_data.inject(ActiveSupport::OrderedHash.new) do |all, row| 238 key = associated ? key_records[row[group_alias].to_i] : type_cast_calculated_value(row[group_alias], group_column) 238 key = type_cast_calculated_value(row[group_alias], group_column) 239 key = key_records[key] if associated 239 240 value = row[aggregate_alias] 240 241 all << [key, type_cast_calculated_value(value, column, operation)] trunk/activerecord/test/calculations_test.rb
r6904 r6919 139 139 assert_equal 2, c[companies(:rails_core)] 140 140 assert_equal 1, c[companies(:first_client)] 141 end 142 143 uses_mocha 'group_by_non_numeric_foreign_key_association' do 144 def test_should_group_by_association_with_non_numeric_foreign_key 145 ActiveRecord::Base.connection.expects(:select_all).returns([{"count_all" => 1, "firm_id" => "ABC"}]) 146 147 firm = mock() 148 firm.expects(:id).returns("ABC") 149 firm.expects(:class).returns(Firm) 150 Company.expects(:find).with(["ABC"]).returns([firm]) 151 152 column = mock() 153 column.expects(:name).at_least_once.returns(:firm_id) 154 column.expects(:type_cast).with("ABC").returns("ABC") 155 Account.expects(:columns).at_least_once.returns([column]) 156 157 c = Account.count(:all, :group => :firm) 158 assert_equal Firm, c.first.first.class 159 assert_equal 1, c.first.last 160 end 141 161 end 142 162