pub struct ModelConfig {
pub table: bool,
pub from_attributes: bool,
pub validate_assignment: bool,
pub extra: ExtraFieldsBehavior,
pub strict: bool,
pub populate_by_name: bool,
pub use_enum_values: bool,
pub arbitrary_types_allowed: bool,
pub defer_build: bool,
pub revalidate_instances: bool,
pub json_schema_extra: Option<&'static str>,
pub title: Option<&'static str>,
}Expand description
Model-level configuration matching Pydantic’s model_config.
This struct holds configuration options that affect model behavior during validation, serialization, and database operations.
§Example
#[derive(Model)]
#[sqlmodel(
table,
from_attributes,
validate_assignment,
extra = "forbid",
strict,
populate_by_name,
use_enum_values
)]
struct User {
// ...
}Fields§
§table: boolWhether this model maps to a database table. If true, DDL can be generated for this model.
from_attributes: boolAllow reading data from object attributes (ORM mode). When true, model_validate can accept objects with attributes in addition to dicts.
validate_assignment: boolValidate field values when they are assigned. When true, assignment to fields triggers validation.
extra: ExtraFieldsBehaviorHow to handle extra fields during validation.
strict: boolEnable strict type checking during validation. When true, types must match exactly (no coercion).
populate_by_name: boolAllow populating fields by either name or alias. When true, both the field name and any aliases are accepted during deserialization.
use_enum_values: boolUse enum values instead of names during serialization. When true, enum fields serialize to their underlying values rather than variant names.
arbitrary_types_allowed: boolAllow arbitrary types in fields. When true, fields can use types that aren’t natively supported by the validation system.
defer_build: boolDefer model validation to allow forward references. When true, validation of field types is deferred until the model is first used.
revalidate_instances: boolRevalidate instances when converting to this model. Controls whether existing model instances are revalidated.
json_schema_extra: Option<&'static str>Custom JSON schema extra data. Additional data to include in generated JSON schema.
title: Option<&'static str>Title for JSON schema generation.
Implementations§
Trait Implementations§
Source§impl Clone for ModelConfig
impl Clone for ModelConfig
Source§fn clone(&self) -> ModelConfig
fn clone(&self) -> ModelConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more