pub struct Field {
pub id: FieldId,
pub name: FieldName,
pub ty: FieldTy,
pub nullable: bool,
pub primary_key: bool,
pub auto: Option<AutoStrategy>,
pub constraints: Vec<Constraint>,
pub variant: Option<VariantId>,
}Expand description
A single field within a model.
Fields are the building blocks of a model’s data structure. Each field has a
unique FieldId, a name, a type (primitive, embedded, or relation), and
metadata such as nullability, primary-key membership, auto-population
strategy, and validation constraints.
§Examples
use toasty_core::schema::app::{Field, Schema};
let schema: Schema = /* ... */;
let model = schema.model(model_id).as_root_unwrap();
for field in &model.fields {
println!("{}: primary_key={}", field.name, field.primary_key);
}Fields§
§id: FieldIdUniquely identifies this field within its containing model.
name: FieldNameThe field’s application and storage names.
ty: FieldTyThe field’s type: primitive, embedded, or a relation variant.
nullable: booltrue if this field accepts None / NULL values.
primary_key: booltrue if this field is part of the model’s primary key.
auto: Option<AutoStrategy>If set, Toasty automatically populates this field on insert.
constraints: Vec<Constraint>Validation constraints applied to this field’s values.
variant: Option<VariantId>If this field belongs to an enum variant, identifies that variant.
None for fields on root models and embedded structs.
Implementations§
Source§impl Field
impl Field
Sourcepub fn primary_key(&self) -> bool
pub fn primary_key(&self) -> bool
Returns true if this field is part of the primary key.
Sourcepub fn auto(&self) -> Option<&AutoStrategy>
pub fn auto(&self) -> Option<&AutoStrategy>
Returns the auto-population strategy, if one is configured.
Sourcepub fn is_auto_increment(&self) -> bool
pub fn is_auto_increment(&self) -> bool
Returns true if this field uses auto-increment for value generation.
Sourcepub fn is_relation(&self) -> bool
pub fn is_relation(&self) -> bool
Returns true if this field is a relation (BelongsTo, HasMany, or
HasOne).
Sourcepub fn full_name(&self, schema: &Schema) -> Option<String>
pub fn full_name(&self, schema: &Schema) -> Option<String>
Returns a fully qualified name for the field.
Sourcepub fn relation_target_id(&self) -> Option<ModelId>
pub fn relation_target_id(&self) -> Option<ModelId>
If the field is a relation, return the relation’s target ModelId.
Sourcepub fn relation_target<'a>(&self, schema: &'a Schema) -> Option<&'a Model>
pub fn relation_target<'a>(&self, schema: &'a Schema) -> Option<&'a Model>
If the field is a relation, return the target of the relation.