<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -14,7 +14,16 @@ module ActiveRecord
             @finder_sql + &quot; AND (#{sanitize_sql(options[:conditions])})&quot;
           options[:include] ||= @reflection.options[:include]
 
-          @reflection.klass.count(column_name, options)
+          value = @reflection.klass.count(column_name, options)
+
+          limit  = @reflection.options[:limit]
+          offset = @reflection.options[:offset]
+
+          if limit || offset
+            [ [value - offset.to_i, 0].max, limit.to_i ].min
+          else
+            value
+          end
         end
       end
 </diff>
      <filename>activerecord/lib/active_record/associations/has_many_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -48,6 +48,12 @@ class HasManyAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal 2, Firm.find(:first).plain_clients.count(:name)
   end
 
+  def test_counting_with_association_limit
+    firm = companies(:first_firm)
+    assert_equal firm.limited_clients.length, firm.limited_clients.size
+    assert_equal firm.limited_clients.length, firm.limited_clients.count
+  end
+
   def test_finding
     assert_equal 2, Firm.find(:first).clients.length
   end</diff>
      <filename>activerecord/test/cases/associations/has_many_associations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>13671cc565aad2327f81a29789154b829ceeda04</id>
    </parent>
  </parents>
  <author>
    <name>Tarmo T&#228;nav</name>
    <email>tarmo@itech.ee</email>
  </author>
  <url>http://github.com/rails/rails/commit/96c6fe084228d570dad80e3100830edb2bc0448d</url>
  <id>96c6fe084228d570dad80e3100830edb2bc0448d</id>
  <committed-date>2008-08-27T23:32:21-07:00</committed-date>
  <authored-date>2008-08-26T09:29:16-07:00</authored-date>
  <message>Implement count limit/offset support for has_many associations

[#348 state:resolved]

Signed-off-by: Jeremy Kemper &lt;jeremy@bitsweat.net&gt;</message>
  <tree>f573cc36df43094cb2b9f7a5cf6ba3406e5edb24</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
