pub struct RelationColumn<M> { /* private fields */ }Expand description
A column showing the record of a Deferred belongs_to or has_one field as text, or the
records of a has_many one (list), which declares the field’s include so every
page that renders it loads them.
use tablo_core::{RelationColumn, lens, relation};
RelationColumn::new::<AuthorResource>(
relation!(Post.author),
lens!(Author.name),
|a: &Author| a.name.clone(),
);The header and the column’s name are the field’s name, capitalized, until
label replaces both. The column neither searches nor sorts.
A column over a source S shows only the related records S shows the user: the ones its
scoped_query returns when it lists
for the user, as a relationship choice over S offers them. A resource’s View policy plays
no part: a related record to hide belongs out of the scoped query, in its
query. A related record it hides, soft-deleted or another
tenant’s, renders empty, and so does every record of a row loaded around the table’s or the
Detail’s loader, which checks them. The row keeps what the include loaded,
so a policy reading the relation sees it whole. unscoped shows whatever
the include loads.
A field field_access restricts shows to a user only
where the user may view it, on every resource the panel mounts over its model: a request that
may not view a field new reads finds no such column. A record’s
label is its title, which the mount keeps clear of every restricted
field, or its key, which no field access may hide.
Implementations§
Source§impl<M> RelationColumn<M>
impl<M> RelationColumn<M>
Sourcepub fn label(self, label: impl Into<Text>) -> Self
pub fn label(self, label: impl Into<Text>) -> Self
Replace the label the field’s name gives it, and name the column after the label,
as a ComputedColumn is: two columns over one relation
need two labels.
Sourcepub fn width(self, width: ColumnWidth) -> Self
pub fn width(self, width: ColumnWidth) -> Self
Declare this column’s width.
Sourcepub fn toggleable(self) -> Self
pub fn toggleable(self) -> Self
Let each reader hide this column from their list; it starts shown.
Let each reader show this column in their list; it starts hidden.
Source§impl<M> RelationColumn<M>
impl<M> RelationColumn<M>
Sourcepub fn new<S>(
relation: RelationLens<M, impl ToOneRelation<S::Model> + 'static>,
reads: impl Into<Reads<S::Model>>,
project: impl Fn(&S::Model) -> String + Send + Sync + 'static,
) -> Selfwhere
S: OptionSource,
pub fn new<S>(
relation: RelationLens<M, impl ToOneRelation<S::Model> + 'static>,
reads: impl Into<Reads<S::Model>>,
project: impl Fn(&S::Model) -> String + Send + Sync + 'static,
) -> Selfwhere
S: OptionSource,
Sourcepub fn of<S>(
relation: RelationLens<M, impl ToOneRelation<S::Model> + 'static>,
) -> Selfwhere
S: OptionSource,
pub fn of<S>(
relation: RelationLens<M, impl ToOneRelation<S::Model> + 'static>,
) -> Selfwhere
S: OptionSource,
Declare a column showing the record relation loads by S’s
label, when S shows it: for a resource, the
record_title its detail page is titled with.
use tablo_core::{RelationColumn, relation};
RelationColumn::of::<AuthorResource>(relation!(Post.author));Sourcepub fn list<S>(relation: RelationLens<M, Deferred<Vec<S::Model>>>) -> Selfwhere
S: OptionSource,
pub fn list<S>(relation: RelationLens<M, Deferred<Vec<S::Model>>>) -> Selfwhere
S: OptionSource,
Declare a column listing the records a has_many relation loads that S shows, a
many-to-many #[has_many(via = ..)] one included, each by S’s
label, joined by commas.
use tablo_core::{RelationColumn, relation};
RelationColumn::list::<TagResource>(relation!(Post.tags));Sourcepub fn unscoped<T>(
relation: RelationLens<M, impl ToOneRelation<T> + 'static>,
project: impl Fn(&T) -> String + Send + Sync + 'static,
) -> Self
pub fn unscoped<T>( relation: RelationLens<M, impl ToOneRelation<T> + 'static>, project: impl Fn(&T) -> String + Send + Sync + 'static, ) -> Self
Declare a column rendering project of whatever record relation loads, under no
resource’s query, policy or field access: for a related model no resource administers. A
panel mounting a resource that restricts a field of the related model refuses it. A row
loaded without the column’s include renders "(unloaded)" and fails a debug assertion.