<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -238,6 +238,8 @@ module ActiveRecord
       def size
         if @owner.new_record? || (loaded? &amp;&amp; !@reflection.options[:uniq])
           @target.size
+        elsif !loaded? &amp;&amp; @reflection.options[:group]
+          load_target.size
         elsif !loaded? &amp;&amp; !@reflection.options[:uniq] &amp;&amp; @target.is_a?(Array)
           unsaved_records = @target.select { |r| r.new_record? }
           unsaved_records.size + count_records</diff>
      <filename>activerecord/lib/active_record/associations/association_collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -249,7 +249,9 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
   end
 
   def test_find_scoped_grouped
+    assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.size
     assert_equal 1, companies(:first_firm).clients_grouped_by_firm_id.length
+    assert_equal 2, companies(:first_firm).clients_grouped_by_name.size
     assert_equal 2, companies(:first_firm).clients_grouped_by_name.length
   end
 </diff>
      <filename>activerecord/test/cases/associations/has_many_associations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>157141b2949b845e372ee703bfd6fba3ffb00415</id>
    </parent>
  </parents>
  <author>
    <name>miloops</name>
    <email>miloops@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/dc8bf7515de85f5bc28d17e96edf4a3e74a858da</url>
  <id>dc8bf7515de85f5bc28d17e96edf4a3e74a858da</id>
  <committed-date>2008-09-15T09:32:05-07:00</committed-date>
  <authored-date>2008-09-15T09:23:50-07:00</authored-date>
  <message>When counting grouped records the target should be loaded to return a valid groups count result.

Without this change count_records will group for the count in the query and return erroneous results.

Signed-off-by: Michael Koziarski &lt;michael@koziarski.com&gt;
[#937 state:committed]</message>
  <tree>3bcc577d8a233d6392b1b78c2b14afe928c2e514</tree>
  <committer>
    <name>Michael Koziarski</name>
    <email>michael@koziarski.com</email>
  </committer>
</commit>
