From 3727f7b8b57272b4bab391b74ff61c9c32b19398 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 25 Aug 2022 12:51:22 +0800 Subject: [PATCH] [examples] create input model with `DeriveIntoActiveModel` (#975) --- examples/basic/src/operation.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/basic/src/operation.rs b/examples/basic/src/operation.rs index 037103f21..cc4aee4a3 100644 --- a/examples/basic/src/operation.rs +++ b/examples/basic/src/operation.rs @@ -70,20 +70,17 @@ mod form { use super::fruit::*; use sea_orm::entity::prelude::*; - #[derive( - Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel, DeriveActiveModelBehavior, - )] - pub struct Model { - pub id: i32, + #[derive(Clone, Debug, PartialEq, Eq, DeriveIntoActiveModel)] + pub struct InputModel { pub name: String, } } async fn save_custom_active_model(db: &DbConn) -> Result<(), DbErr> { - let pineapple = form::ActiveModel { - id: NotSet, - name: Set("Pineapple".to_owned()), - }; + let pineapple = form::InputModel { + name: "Pineapple".to_owned(), + } + .into_active_model(); let pineapple = pineapple.save(db).await?;