Trying to get a definitive answer on whether it’s possible to limit a delete_all to X number of records.
I’m trying the following:
Model.where(:account_id => account).order(:id).limit(1000).delete_all
but it doesn’t seem to respect the limit and instead just deletes all Model where :account_id => account.
I would expect it to generate the following:
delete from model where account_id = ? order by id limit 1000
This seems to work fine when using destroy_all but I want to delete in bulk.
You have to use send because ‘delete_sql’ is protected, but this works.
I found that removing the ‘order by’ significantly sped it up too.
I do think it’s weird that using
.limitworks withdestroy_allbut notdelete_all