Destroying / Deleting persistent instances

Destroying / Deleting persistent instances

Once you created an object and got a reference to it, you can delete it from the database. The relevant method is destroy:

Task.create({ title: 'a task' }).then(task => {
  // now you see me...
  return task.destroy();
}).then(() => {
 // now i'm gone :)
})

If the paranoid options is true, the object will not be deleted, instead the deletedAt column will be set to the current timestamp. To force the deletion, you can pass force: true to the destroy call:

task.destroy({ force: true })

After an object is soft deleted in paranoid mode, you will not be able to create a new instance with the same primary keyuntil you have force-deleted the old instance.