Skip to main content

ModelColumns

Trait ModelColumns 

Source
pub trait ModelColumns:
    Model
    + IntoExpr<Self>
    + Sized {
    const TENANT_COLUMNS: &'static [&'static str];
    const UNLOADS_RELATIONS: bool = false;

    // Provided methods
    fn table() -> Table<Self> { ... }
    fn detail() -> Detail<Self> { ... }
    fn version(&self) -> Option<u64> { ... }
    fn bare(&self) -> Self
       where Self: Clone { ... }
    fn references(&self) -> Vec<(&'static str, Option<String>)> { ... }
}
Expand description

The table and detail page a model reads as when its resource declares none: what a ResourceDef without a table lists and without a detail shows.

Derive it with ModelColumns, which gives a column to each field a person reads, whether a form or Toasty writes it. An impl by hand names the model’s tenant columns; one that keeps the defaults here lists no column, for a resource that declares its own table and detail page, or turns the view page off.

Required Associated Constants§

Source

const TENANT_COLUMNS: &'static [&'static str]

The model’s TenantId fields, by name: the derive lists each field typed TenantId or Option<TenantId>. Mounting a panel refuses a resource over a model that lists one and declares no tenancy, which would serve every tenant’s rows. It has no default, so an impl by hand states it.

Provided Associated Constants§

Source

const UNLOADS_RELATIONS: bool = false

Whether bare leaves out every relation the model holds. The derive answers true when each relation is a Deferred one; an impl by hand keeps this default unless its bare leaves them out.

A panel then hands a closure over the row that declares it reads none, such as a row_color, a copy of the row without them, so the closure mounts beside a column loading a record of a model a resource restricts a field of. Such a closure reaching a relation anyway panics at render, where it read the relation another column loaded before: declare the relations it reads.

An eager relation, typed without Deferred, holds its records on every query, so a model with one answers false and keeps the refusal.

Provided Methods§

Source

fn table() -> Table<Self>

The default table, which lists no column here.

Source

fn detail() -> Detail<Self>

The default detail page, which lists no column here: a resource serving the view page then declares its own, else mounting refuses it.

Source

fn version(&self) -> Option<u64>

The record’s #[version] counter, or None for a model without one.

The edit form carries it, so a save refuses a record another save changed since the form opened. The derive reads the model’s #[version] field; an impl written by hand keeps this default unless it returns the counter itself.

Source

fn bare(&self) -> Self
where Self: Clone,

A copy of the record without its relations, holding its own fields: the derive builds it field by field, leaving each Deferred relation unloaded rather than copying its records.

Source

fn references(&self) -> Vec<(&'static str, Option<String>)>

The record’s foreign keys and TenantId fields, by name, each spelled as the database stores it, None where it holds nothing.

The default table leaves them out, so a ChangedField reads them here: moving a record to another owner or tenant is a change a write names. The derive lists them; an impl by hand keeps this default, which lists none.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§