Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Soft Delete

Delete moves a record to the trash. A trashed record leaves every list, form and export until it is restored or deleted permanently.

Add the column

use laterite_core::strata::*;

Table::create()
    .table(Alias::new("notes"))
    .col(ColumnDef::new(Alias::new("id")).big_integer().not_null().auto_increment().primary_key())
    .col(ColumnDef::new(Alias::new("title")).text().not_null())
    .col(soft_delete_col())
    .to_owned()

soft_delete_col() is a nullable deleted_at column.

Turn it on

entity: notes
path: /notes
title: Notes
permission: acme.manage_notes
soft_delete: true
list:
  deletable: true
  columns:
    title: {}
Resource::new("/notes", t!("Notes"), list).soft_delete()

The list

ViewButtonsRoute
The listDelete moves the selection to the trash; Trash opens the trashPOST {path}/delete
The trash (?trashed=1)Restore; Delete permanently; Leave the trashPOST {path}/restore, POST {path}/purge

A trashed record has no edit page. Delete permanently removes only records that are in the trash.

A trash and a restore are saves: model listeners, timestamps, footprints and the audit log see an update of deleted_at.

relations:
  comments:
    entity: comments
    foreign_key: note_id
    soft_delete: true
    list:
      columns:
        body: {}
    form:
      fields:
        body: {}
EventRelated rows
The parent is trashedEach live row takes the parent’s deleted_at value
The parent is restoredRows carrying that same value are restored; a row trashed on its own stays in the trash

The related table needs soft_delete_col() too. The section’s own Delete removes a row permanently.

Leave trashed rows out of a picker

TableSource::new("notes", "id", "title").scope(Arc::new(SoftDelete))

A search skips trashed rows; a stored id still shows its label.