This project is archived and is in readonly mode.

#305 ✓resolved
sds

Size reports incorrectly for collections when more than one item is added with build

Reported by sds | June 2nd, 2008 @ 10:48 PM

Adding more than one item to a collection using collection.build and then subsequently checking the size of the collection with the size method fails to work correctly.

This code from active_record/associations/association_collection.rb:

unsaved_records = Array(@target.detect { |r| r.new_record? })

unsaved_records.size + count_records

should read:

unsaved_records = Array(@target.select { |r| r.new_record? })

unsaved_records.size + count_records

I attach a git diff for patching the code and adding a test for this.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages