Generation & ModelSchema
What `model!(...)` generates
From the DSL read by runique_dsl, the macro generates, among others:
- the SeaORM entity (
Model,Entity,Column,ActiveModel) and its relations (belongs_totargets the related entity's real primary key, with its actions); - the
ActiveModelBehaviorthat fillsauto_now/auto_now_update; - one Rust enum per entry of the
enums:block; - the
AdminFormand the functions the admin uses; - for each list field (
multichoice/checkbox), the entity of its table and the methodsfield(),set_field(),load_field(); - a
schema() -> ModelSchemafunction.
pub fn schema() -> runique::migration::schema::ModelSchema {
runique::migration::ModelSchema::new("User")
.table_name("users")
// pk, columns (types, bounds, enums), FK, indexes, meta...
.build()
.unwrap()
}
Role of `ModelSchema`
ModelSchema describes the model's columns (types, declared bounds, enums, foreign keys, indexes) for forms. It isn't used for migrations: makemigrations reads the DSL directly. List fields aren't part of it, having no column.
Methods used by forms
fill_form(form, fields, exclude): fills a#[form(schema = ...)]form from the schema;enforce_limits(form): called aftercustomize, checks the form didn't loosen what the model declares (min_length,max_length,min,max, integer type, password field) — panics otherwise.
fill_form behavior
- the PK is always excluded,
- if
fieldsis provided: whitelist takes priority (order preserved), - otherwise
excludeis used as a blacklist.