#[derive(ModelColumns)]
{
// Attributes available to this derive:
#[columns]
}
Expand description
Derive a model’s ModelColumns: the table a resource lists it in and
the detail page it shows it on, when the resource declares neither.
#[derive(Debug, Clone, toasty::Model, tablo_core::ModelColumns)]
pub struct User {
#[key]
#[auto]
pub id: uuid::Uuid,
pub name: String,
pub role: Role,
pub active: bool,
#[columns(skip)]
pub password_hash: String,
#[default(jiff::Timestamp::now())]
pub created_at: jiff::Timestamp,
}
// Lists `name`, `role`, `active` and `created_at`, and shows them on the detail page.
let table = <User as tablo_core::ModelColumns>::table();Each field shows whoever writes it, the person through a form or Toasty through a
#[default] or an #[update], in a column its type picks:
- a
bool: a sortableBooleanColumn, yes or no; - a
StringorOption<String>: a sortable, searchableTextColumn; - any other
FormScalar: a sortableTextColumn, anOptionsenum by its label; - an
EmbeddedFormvalue: anEmbeddedColumn, leaf by leaf, on the detail page only; - a list of
RepeaterItemvalues: aRepeaterColumn, on the detail page only; - any other type: no column.
No column shows a key Toasty generates, a #[version] field, a relation or its foreign
key, which only a declared RelationColumn shows, by the related record’s title, or a
TenantId or Option<TenantId> field, which belongs to the resource’s Tenancy. An
#[auto] created_at or updated_at shows like any timestamp.
Every other field shows, a secret such as a password hash or an API token included, to
anyone the policy lets view the list: mark it #[columns(skip)], which leaves it out of
the table, its search and export, and the detail page. On a field already left out it is a
compile error, as are an unknown key and a generic model.
The derive reads the model, not a form: a file path shows as text and a String an
#[form(options = ..)] key labels shows its stored value. Declare a FileColumn or a
formatted TextColumn for them.
A resource replaces either default with ResourceDef::table or ResourceDef::detail,
and extends one by starting from it: User::table().filters(..), with
ModelColumns in scope.
Derive a model’s default table and detail page; documented on the tablo-core re-export.