Skip to content
Tags

,

delete vs destroy

February 23, 2011

I have wondered about what the difference might be:

I have seen times when the .delete method keeps the record in the database table and only set the value of a :deleted_at field.
Now this could be because  the delete method could have been overwritten in that particular situation. Also not all records have a deleted_at order and neither is it consistently true that .delete method does not delete the record. I have seen it do it.

It seeems that the link i paste below might give a better understanding of the difference between the true. In short. destroy takes long, but is your friend. delete is fast, but could keep an uwanted mark:

Delete method deletes the row with a primary key matching the id argument, using a SQL DELETE statement, and returns the number of rows deleted. Active Record objects are not instantiated, so the object‘s callbacks are not executed, including any :dependent association options or Observer methods.

http://www.rorexperts.com/difference-between-delete-and-destroy-in-activerecord-t1357.html

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: