pub struct ModelRoot {
pub id: ModelId,
pub name: Name,
pub fields: Vec<Field>,
pub primary_key: PrimaryKey,
pub table_name: Option<String>,
pub indices: Vec<Index>,
}Expand description
A root model backed by its own database table.
Root models have a primary key, may define indices, and are the only model kind that can be the target of relations. They are the main entities users interact with through Toasty’s query API.
§Examples
let root = model.as_root_unwrap();
let pk_fields: Vec<_> = root.primary_key_fields().collect();Fields§
§id: ModelIdUniquely identifies this model within the schema.
name: NameThe model’s name.
fields: Vec<Field>All fields defined on this model.
primary_key: PrimaryKeyThe primary key definition. Root models always have a primary key.
table_name: Option<String>Optional explicit table name. When None, a name is derived from the
model name.
indices: Vec<Index>Secondary indices defined on this model.
Implementations§
Source§impl ModelRoot
impl ModelRoot
Sourcepub fn find_by_id(&self, input: impl Input) -> Query
pub fn find_by_id(&self, input: impl Input) -> Query
Builds a SELECT query that filters by this model’s primary key using
the supplied input to resolve argument values.
Sourcepub fn primary_key_fields(&self) -> impl ExactSizeIterator<Item = &Field>
pub fn primary_key_fields(&self) -> impl ExactSizeIterator<Item = &Field>
Iterate over the fields used for the model’s primary key.
Sourcepub fn field_by_name(&self, name: &str) -> Option<&Field>
pub fn field_by_name(&self, name: &str) -> Option<&Field>
Looks up a field by its application-level name.
Returns None if no field with that name exists on this model.
Trait Implementations§
Source§impl<'a, T> IntoExprTarget<'a, T> for &'a ModelRoot
impl<'a, T> IntoExprTarget<'a, T> for &'a ModelRoot
Source§fn into_expr_target(self, _schema: &'a T) -> ExprTarget<'a>
fn into_expr_target(self, _schema: &'a T) -> ExprTarget<'a>
self into an ExprTarget using the provided schema.