[examples] create input model with DeriveIntoActiveModel (#975)

This commit is contained in:
Billy Chan 2022-08-25 12:51:22 +08:00 committed by GitHub
parent 87f7891f17
commit 3727f7b8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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?;