Is there a quicker way of doing destroy all in rails?
I'm asking this because rails does an individual delete sql query per record.
For example calling destroy all on a search for 4 records would then run 4 delete sql commands.
Blerg.where("created_at > yesterday").destroy_all (4 results)
then calles…
DELETE FROM "blergs" WHERE "blergs"."id" = $1 [["id", 197782]]
4 times.
Is there a way to get it into one sql command?
You can allways call
Blerg.where("created_at > yesterday").delete_all
This gives only one query:
DELETE FROM "blergs" WHERE (created_at > '2012-11-26 16:27:56.678872')
Note that this does not call any callbacks on the objects which are to be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With