This project is archived and is in readonly mode.

#5568 ✓stale
Will Bryant

2.3.9 destroy_all destroys loaded records that do not match the scope on associations

Reported by Will Bryant | September 7th, 2010 @ 10:32 AM

Release 2.3.9's commit https://github.com/rails/rails/commit/b41c3ba154c2038ecc7b230693662... introduced a nasty bug that causes some_association.some_scope.destroy_all to destroy any records that were loaded in some_association, even if they do not match some_scope.

For example, see the attached test case, where I create some records on an association, and then destroy_all on a scope of that association.

In ActiveRecord::Associations::AssociationCollection#load_target, the new code adds back all the records in @target, which are then returned in the target array to destroy_all, which then destroys them.

This didn't previously happen as that method previously only added back in any new records. So I have attached a patch that solves this particular case by only adding back the new records. This restores the prior behavior in this respect

One could argue though that this whole method needs a rewrite to have clearer semantics with respect to scopes.

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>

Attachments

Pages