Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a record from database

In Ruby on Rails, is it @variable.delete or @variable.destroy

like image 524
Justin Meltzer Avatar asked Mar 19 '11 07:03

Justin Meltzer


People also ask

Can you delete data from database?

To delete data or log files from a database Select the Files page. In the Database files grid, select the file to delete and then click Remove.


1 Answers

@variable.destroy will call all callbacks (before_destroy etc.) as well as ensure associations are respected. @variable.delete just calls the raw database query to delete the object. You're generally much safer off using destroy even if it's more expensive.

like image 73
lebreeze Avatar answered Oct 13 '22 14:10

lebreeze