#[derive(ToCreateModel)]
{
// Attributes available to this derive:
#[crudcrate]
#[active_model]
}
Expand description
§===================
ToCreateModel Macro
This macro:
- Generates a struct named
<OriginalName>Createthat includes only the fields where#[crudcrate(create_model = false)]is NOT specified (default = true). If a field has anon_createexpression, its type becomesOption<…>(with#[serde(default)]) so the user can override that default. - Generates an
impl From<<OriginalName>Create> for <ActiveModelType>>where:- For each field with
on_create:- If the original type was
Option<T>, thencreate.<field>isOption<Option<T>>. We match on that and do:ⓘmatch create.field { Some(Some(v)) => Some(v.into()), // user overrode with T Some(None) => None, // user explicitly set null None => Some((expr).into()), // fallback to expr } - If the original type was non‐optional
T, thencreate.<field>isOption<T>. We match on that and do:ⓘmatch create.field { Some(v) => v.into(), None => (expr).into(), }
- If the original type was
- For each field without
on_create:- If the original type was
Option<T>, we docreate.<field>.map(|v| v.into()). - If it was non‐optional
T, we docreate.<field>.into().
- If the original type was
- For any field excluded (
create_model = false) but havingon_create, we doSome((expr).into())if it wasOption<T>, or just(expr).into()otherwise.
- For each field with