Deleting a model works – very similar to update and create – like this:
user.delete(on: request.db) // returns EventLoopFuture<Void>
Vapor differentiates between a hard and a soft delete. A hard delete means the entry is deleted from the database. A soft delete only marks an entry as deleted – which says it can be restored.
To enable soft deletes, you have to specify the key to the variable/column in the model like this:
final class MyModel: Model {
// ...
@Field(key: "deletedAt")
var deletedAt: Date?
}
It is usually best to use a soft delete, at least for a while. You can always delete them later; however, in practical terms, it has proven beneficial to keep entries for at least a few days after they are deleted.