rails/rails — Issue #4979: delete_all should respect a limit scope
Author: daveyeu
Created: 2012-02-09 20:35:28+00:00
State: open

Hi there,

So we _nearly_ just hosed a table in production by trying:

Model.limit(100).delete_all

Thankfully, we decided to read up on how delete_all works here and tested it locally, since it turns out that this simply deletes everything in the table.

Now I get that a LIMIT clause doesn't make sense on a DELETE op, but can we add a sensible translation in this case? I would expect it to behave like .destroy_all, which appears to instantiate the records and call #destroy on each. A #delete_all wouldn't have to inflate AR objects here, but instead, could simply query for the ids to delete, and then perform a DELETE FROM ... id IN (...) query.

Thoughts? I think we can prevent some future pain here.

Thanks,

Dave & John