Skip to main content
zerotal

Documentation


Documentation / @zerotal/orm / index / SoftDeletes

Function: SoftDeletes()

SoftDeletes<TBase>(Base): {(...args): SoftDeletes; softDeletes: boolean; withTrashed: ModelQueryBuilder<T>; onlyTrashed: ModelQueryBuilder<T>; prototype: SoftDeletes<any>; } & TBase

Defined in: packages/orm/src/model/SoftDeletes.ts:61

Mixin that adds opt-in soft deletes to a model. Compose it so only models that want them carry the API — deletedAt, SoftDeletes.forceDelete, SoftDeletes.restore, SoftDeletes.trashed, and the SoftDeletes.withTrashed / SoftDeletes.onlyTrashed query scopes.

The mixin flips static softDeletes = true, which is what the query engine and schema sync read: every default query scopes WHERE deleted_at IS NULL, the migrator provisions a deleted_at column, and delete() sets deleted_at instead of removing the row.

Type Parameters

TBase

TBase extends Constructor

Parameters

Base

TBase

Returns

Example

@table("posts")
class Post extends BaseModelWith(SoftDeletes) {
  @column() title!: string;
}

await post.delete();               // sets deleted_at; hidden from default queries
await Post.withTrashed().get();     // includes soft-deleted rows
await Post.onlyTrashed().get();     // only soft-deleted rows
await post.restore();               // deleted_at = NULL
await post.forceDelete();           // permanent DELETE