Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there destroy_all!/delete_all! in Rails?

We are looking for a command to delete multiple records within Rails transaction. To make it trigger within transaction, we used destroy_all! and delete_all! and received method not defined error. What's the right delete command (or right way) for multiple records which triggers in Rails transaction?

like image 537
user938363 Avatar asked Oct 03 '15 23:10

user938363


1 Answers

No, there are no methods called delete_all! or destroy_all!. See the documentation.

Use delete_all or destroy_all instead. These methods will raise ActiveRecord errors if deletion fails. It means your transaction will be rolled back in case of errors as you expected.

like image 99
Hoa Avatar answered Oct 10 '22 02:10

Hoa