This project is archived and is in readonly mode.
ActiveRecord `destroy_all` returns empty array instead of destroyed records
Reported by Mislav | July 8th, 2010 @ 01:19 PM
Just noticed a regression in Rails 3: destroy_all
always returns an empty array. I've added tests to master and
2-3-stable that destroy_all
should return destroyed,
frozen records same as destroy
class method does. I've
fixed the failure in Rails 3 and also fixed
destroy_all
on associations in both Rails 3 and
2.3.
- Fix for master is in
mislav/destroy_all-fix
- Fix for 2.3 is in mislav/destroy_all-2-3-stable
Comments and changes to this ticket
-
Neeraj Singh July 8th, 2010 @ 01:57 PM
- State changed from new to open
- Importance changed from to Low
to_a.each {|object| object.destroy }.tap { reset }
What if destroy operation fails on an object. In that case even the failed object will show up in the returned collection. I think changing 'each' to 'select' might fix that problem.
If you don't mind can you add test for this edge condition. Thanks.
-
Mislav July 8th, 2010 @ 03:48 PM
That wasn't a behavior of Rails 2.3. Why change it? A user can iterate over the "destroyed" objects collection and check which records are truly
destroyed?
and which have failed because ofbefore_destroy
callbacks.But you're right: whatever behavior is in place, it should be tested.
-
Mislav July 8th, 2010 @ 04:22 PM
Heads-up to those who might have already pulled: I've just force-pushed something I forgot to my branch for master.
-
Jeremy Kemper July 8th, 2010 @ 07:37 PM
- State changed from open to committed
Cherry-picked. Thanks Mislav!
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>