InterviewSolution
| 1. |
What Is The Difference Between Delete And Destroy ? |
|
Answer» The DELETE METHOD essentially deletes a row (or an array of rows) from the DATABASE. Destroy on the other hand allows for a few more options. First, it will check any callbacks such as before_delete, or any dependencies that we specify in our model. Next, it will keep the object that just got deleted in memory; this allows us to LEAVE a message saying something like “ 'Object_name' has been deleted.” Lastly, and most importantly, it will also delete any child objects ASSOCIATED with that object! The delete method essentially deletes a row (or an array of rows) from the database. Destroy on the other hand allows for a few more options. First, it will check any callbacks such as before_delete, or any dependencies that we specify in our model. Next, it will keep the object that just got deleted in memory; this allows us to leave a message saying something like “ 'Object_name' has been deleted.” Lastly, and most importantly, it will also delete any child objects associated with that object! |
|