Generation & ModelSchema
Code generated by model!(...)
After parsing the AST, the macro generates, among other things:
- a
schema() -> ModelSchemafunction - the SeaORM model (generated code)
- associated relations
The generated schema() function follows this pattern:
pub fn schema() -> runique::migration::schema::ModelSchema {
runique::migration::ModelSchema::new("User")
.table_name("users")
// pk, columns, FK, relations, meta...
.build()
.unwrap()
}
Role of `ModelSchema`
ModelSchema is the structural source of truth (table, PK, columns, FK, relations, indexes).
Important runtime methods
to_migration(): generates the migration statementfill_form(form, fields, exclude): populates a form from the schema
fill_form behavior
- the primary key is always excluded,
- if
fieldsis provided: it acts as a whitelist (order preserved), - otherwise
excludeacts as a blacklist.