#[derive(ToUpdateModel)]
{
// Attributes available to this derive:
#[crudcrate]
#[active_model]
}
Expand description
§===================
ToUpdateModel Macro
This macro:
- Generates a struct named
<OriginalName>Updatethat includes only the fields where#[crudcrate(update_model = false)]is NOT specified (default = true). - Generates an impl for a method
merge_into_activemodel(self, mut model: ActiveModelType) -> ActiveModelTypethat, for each field:- If it’s included in the update struct, and the user provided a value:
- If the original field type was
Option<T>, we match onOption<Option<T>>:ⓘSome(Some(v)) => ActiveValue::Set(Some(v.into())), Some(None) => ActiveValue::Set(None), // explicit set to None None => ActiveValue::NotSet, // no change - If the original field type was non‐optional
T, we match onOption<T>:ⓘSome(val) => ActiveValue::Set(val.into()), _ => ActiveValue::NotSet,
- If the original field type was
- If it’s excluded (
update_model = false) but hason_update = expr, we doActiveValue::Set(expr.into())(wrapped inSome(...)if the original field wasOption<T>). - All other fields remain unchanged.
- If it’s included in the update struct, and the user provided a value: