This project is archived and is in readonly mode.
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
-
sds June 2nd, 2008 @ 11:23 PM
Actually the creation of a new array in the patched version is not needed (select already returns an array), I attach new patch containing this code:
unsaved_records = @target.select { |r| r.new_record? }
unsaved_records.size + count_records
-
Repository July 2nd, 2008 @ 03:21 AM
- Tag set to activerecord, bug, patch
(from [474d42538269a141687c7c66bef6575b4682b15d]) Ensure AssociationCollection#size considers all unsaved record. [#305 state:resolved] [sds]
Signed-off-by: Pratik Naik
-
Pratik July 2nd, 2008 @ 04:21 AM
- State changed from new to resolved
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>