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:

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

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:

  1. 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.