What Is The Difference Between Delete And Destroy?

Technology CommunityCategory: Ruby on RailsWhat Is The Difference Between Delete And Destroy?
VietMX Staff asked 3 years ago
  • 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.