<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer" nil="true"></assigned-user-id>
  <attachments-count type="integer">1</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2008-08-19T23:54:09+01:00</created-at>
  <creator-id type="integer">11378</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer">9903</milestone-id>
  <number type="integer">865</number>
  <permalink>fix-count_records</permalink>
  <priority type="integer">321</priority>
  <project-id type="integer">8994</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>resolved</state>
  <tag>activerecord bug patch</tag>
  <title>fix count_records</title>
  <updated-at type="datetime">2008-08-25T09:31:01+01:00</updated-at>
  <user-id type="integer">17393</user-id>
  <user-name>Repository</user-name>
  <creator-name>Xavier Noria</creator-name>
  <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
  <milestone-title>2.x</milestone-title>
  <original-body>This is a patch related to &quot;this thread in rubyonrails-core&quot;:http://groups.google.com/group/rubyonrails-core/browse_thread/thread/15d2917c8fe02bec.

In a has many association `count_records` basically counts by SQL. If there are no children in the database it assumes that's enough to say there are no children at all. That's not necessarily the case because the association could have new records in @target.

There are several ways to observe this behaviour, for example rendering a collection that has only new records (via #build) would render nothing at all.

This minimal test depicts the issue as well:

@@@ ruby
post = Post.create
post.comments.build
post.comments.size # =&gt; 1
post.comments.size # =&gt; 0
@@@

The fix turns out to be simple. I've added a regression test as well.

The documentation I mention in a comment will eventually be merged from &quot;this patch in docrails&quot;:http://github.com/lifo/docrails/commit/2ee60b0f70febc8c28a90e8361d9e9c2b86d4833.</original-body>
  <latest-body>This is a patch related to &quot;this thread in rubyonrails-core&quot;:http://groups.google.com/group/rubyonrails-core/browse_thread/thread/15d2917c8fe02bec.

In a has many association `count_records` basically counts by SQL. If there are no children in the database it assumes that's enough to say there are no children at all. That's not necessarily the case because the association could have new records in @target.

There are several ways to observe this behaviour, for example rendering a collection that has only new records (via #build) would render nothing at all.

This minimal test depicts the issue as well:

@@@ ruby
post = Post.create
post.comments.build
post.comments.size # =&gt; 1
post.comments.size # =&gt; 0
@@@

The fix turns out to be simple. I've added a regression test as well.

The documentation I mention in a comment will eventually be merged from &quot;this patch in docrails&quot;:http://github.com/lifo/docrails/commit/2ee60b0f70febc8c28a90e8361d9e9c2b86d4833.</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;This is a patch related to &lt;a href=&quot;http://groups.google.com/group/rubyonrails-core/browse_thread/thread/15d2917c8fe02bec&quot;&gt;this thread in rubyonrails-core&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a has many association &lt;code&gt;count_records&lt;/code&gt; basically counts by SQL. If there are no children in the database it assumes that's enough to say there are no children at all. That's not necessarily the case because the association could have new records in @target.&lt;/p&gt;

&lt;p&gt;There are several ways to observe this behaviour, for example rendering a collection that has only new records (via #build) would render nothing at all.&lt;/p&gt;

&lt;p&gt;This minimal test depicts the issue as well:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
post = Post.create
post.comments.build
post.comments.size # =&amp;gt; 1
post.comments.size # =&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The fix turns out to be simple. I've added a regression test as well.&lt;/p&gt;

&lt;p&gt;The documentation I mention in a comment will eventually be merged from &lt;a href=&quot;http://github.com/lifo/docrails/commit/2ee60b0f70febc8c28a90e8361d9e9c2b86d4833&quot;&gt;this patch in docrails&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>This is a patch related to &quot;this thread in rubyonrails-core&quot;:http://groups.google.com/group/rubyonrails-core/browse_thread/thread/15d2917c8fe02bec.

In a has many association `count_records` basically counts by SQL. If there are no children in the database it assumes that's enough to say there are no children at all. That's not necessarily the case because the association could have new records in @target.

There are several ways to observe this behaviour, for example rendering a collection that has only new records (via #build) would render nothing at all.

This minimal test depicts the issue as well:

@@@ ruby
post = Post.create
post.comments.build
post.comments.size # =&gt; 1
post.comments.size # =&gt; 0
@@@

The fix turns out to be simple. I've added a regression test as well.

The documentation I mention in a comment will eventually be merged from &quot;this patch in docrails&quot;:http://github.com/lifo/docrails/commit/2ee60b0f70febc8c28a90e8361d9e9c2b86d4833.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This is a patch related to &lt;a href=&quot;http://groups.google.com/group/rubyonrails-core/browse_thread/thread/15d2917c8fe02bec&quot;&gt;this thread in rubyonrails-core&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a has many association &lt;code&gt;count_records&lt;/code&gt; basically counts by SQL. If there are no children in the database it assumes that's enough to say there are no children at all. That's not necessarily the case because the association could have new records in @target.&lt;/p&gt;

&lt;p&gt;There are several ways to observe this behaviour, for example rendering a collection that has only new records (via #build) would render nothing at all.&lt;/p&gt;

&lt;p&gt;This minimal test depicts the issue as well:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
post = Post.create
post.comments.build
post.comments.size # =&amp;gt; 1
post.comments.size # =&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The fix turns out to be simple. I've added a regression test as well.&lt;/p&gt;

&lt;p&gt;The documentation I mention in a comment will eventually be merged from &lt;a href=&quot;http://github.com/lifo/docrails/commit/2ee60b0f70febc8c28a90e8361d9e9c2b86d4833&quot;&gt;this patch in docrails&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-19T23:54:09+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-19T23:54:09+01:00</updated-at>
      <user-id type="integer">11378</user-id>
      <user-name>Xavier Noria</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Patch updated with Fred's proposal. That one is better because we certainly can assert `loaded` anyway.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Patch updated with Fred's proposal. That one is better because we certainly can assert &lt;code&gt;loaded&lt;/code&gt; anyway.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-20T00:22:45+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-20T00:22:45+01:00</updated-at>
      <user-id type="integer">11378</user-id>
      <user-name>Xavier Noria</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Looks good to me, tests pass. Perhaps the assert should assert that the size is 1 (or is that already covered by existing tests ?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Looks good to me, tests pass. Perhaps the assert should assert that the size is 1 (or is that already covered by existing tests ?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-20T11:33:52+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-20T11:33:52+01:00</updated-at>
      <user-id type="integer">17477</user-id>
      <user-name>Frederick Cheung</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Yeah, the test assumes size1 is correct because there are unit tests for #size in test_build and test_collection_size_after_building.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Yeah, the test assumes size1 is correct because there are unit tests for #size in test_build and test_collection_size_after_building.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-20T11:55:31+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-20T11:55:31+01:00</updated-at>
      <user-id type="integer">11378</user-id>
      <user-name>Xavier Noria</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I don't think it's necessary to refer to google groups threads in a comment. Either explain the issue in a comment (if it really needs explaining) or don't add a comment. When the patch is commited the added code will already be tied to the commit (git annotate) which will refer to this ticket which already refers to the google groups thread.

Other than that, +1</body>
      <body-html>&lt;div&gt;&lt;p&gt;I don't think it's necessary to refer to google groups threads in a comment. Either explain the issue in a comment (if it really needs explaining) or don't add a comment. When the patch is commited the added code will already be tied to the commit (git annotate) which will refer to this ticket which already refers to the google groups thread.&lt;/p&gt;

&lt;p&gt;Other than that, +1&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-20T18:49:33+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-20T18:49:33+01:00</updated-at>
      <user-id type="integer">14890</user-id>
      <user-name>Tarmo T&#228;nav</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>(from [a970f916fb1e05376733e2d42d9bcc2b873af355]) Fix has_many#count_records. [#865 state:resolved]

Signed-off-by: Pratik Naik &lt;pratiknaik@gmail.com&gt;
http://github.com/rails/rails/commit/a970f916fb1e05376733e2d42d9bcc2b873af355</body>
      <body-html>&lt;div&gt;&lt;p&gt;(from [a970f916fb1e05376733e2d42d9bcc2b873af355]) Fix has_many#count_records. [&lt;a href=&quot;/projects/8994/tickets/865&quot; title=&quot;Ticket #865&quot;&gt;#865&lt;/a&gt; state:resolved]&lt;/p&gt;

&lt;p&gt;Signed-off-by: Pratik Naik &lt;a&gt;&amp;#112;&amp;#x72;&amp;#97;&amp;#x74;&amp;#105;&amp;#107;&amp;#110;&amp;#x61;&amp;#105;&amp;#x6b;&amp;#x40;&amp;#x67;&amp;#109;&amp;#x61;&amp;#105;&amp;#108;&amp;#x2e;&amp;#x63;&amp;#111;&amp;#109;&lt;/a&gt;
&lt;a href=&quot;http://github.com/rails/rails/commit/a970f916fb1e05376733e2d42d9bcc2b873af355&quot;&gt;http://github.com/rails/rails/co...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2008-08-21T15:51:04+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>resolved</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-21T15:51:04+01:00</updated-at>
      <user-id type="integer">17393</user-id>
      <user-name>Repository</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>(from [0048f558e69cfc2675552dd31ea773b2b8271e9b]) Fix has_many#count_records. [#865 state:resolved]

Signed-off-by: Pratik Naik &lt;pratiknaik@gmail.com&gt;
http://github.com/rails/rails/commit/0048f558e69cfc2675552dd31ea773b2b8271e9b</body>
      <body-html>&lt;div&gt;&lt;p&gt;(from [0048f558e69cfc2675552dd31ea773b2b8271e9b]) Fix has_many#count_records. [&lt;a href=&quot;/projects/8994/tickets/865&quot; title=&quot;Ticket #865&quot;&gt;#865&lt;/a&gt; state:resolved]&lt;/p&gt;

&lt;p&gt;Signed-off-by: Pratik Naik &lt;a&gt;&amp;#x70;&amp;#114;&amp;#97;&amp;#116;&amp;#105;&amp;#107;&amp;#x6e;&amp;#x61;&amp;#x69;&amp;#107;&amp;#x40;&amp;#x67;&amp;#109;&amp;#x61;&amp;#105;&amp;#x6c;&amp;#46;&amp;#x63;&amp;#x6f;&amp;#x6d;&lt;/a&gt;
&lt;a href=&quot;http://github.com/rails/rails/commit/0048f558e69cfc2675552dd31ea773b2b8271e9b&quot;&gt;http://github.com/rails/rails/co...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2008-08-25T09:31:01+01:00</created-at>
      <creator-id type="integer">11378</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">865</number>
      <permalink>fix-count_records</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>resolved</state>
      <tag>activerecord bug patch</tag>
      <title>fix count_records</title>
      <updated-at type="datetime">2008-08-25T09:31:01+01:00</updated-at>
      <user-id type="integer">17393</user-id>
      <user-name>Repository</user-name>
      <creator-name>Xavier Noria</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/865</url>
      <milestone-title>2.x</milestone-title>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>97e7c7e94849d411ebc6f07879877e0812c20d52</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2008-08-20T00:22:45+01:00</created-at>
      <filename>fix_count_records_2.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">40285</id>
      <size type="integer">2623</size>
      <uploader-id type="integer">11378</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/40285/fix_count_records_2.diff</url>
    </attachment>
  </attachments>
</ticket>
