diff --git a/sea-orm-macros/src/derives/active_model.rs b/sea-orm-macros/src/derives/active_model.rs index 76e80a02..4d18a169 100644 --- a/sea-orm-macros/src/derives/active_model.rs +++ b/sea-orm-macros/src/derives/active_model.rs @@ -71,7 +71,11 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result::Column) -> sea_orm::ActiveValue { match c { - #(::Column::#name => std::mem::take(&mut self.#field).into_wrapped_value(),)* + #(::Column::#name => { + let mut value = sea_orm::ActiveValue::unset(); + std::mem::swap(&mut value, &mut self.#field); + value.into_wrapped_value() + },)* _ => sea_orm::ActiveValue::unset(), } } diff --git a/tests/bakery_chain/order.rs b/tests/bakery_chain/order.rs index ce6418a2..41bfb03f 100644 --- a/tests/bakery_chain/order.rs +++ b/tests/bakery_chain/order.rs @@ -17,7 +17,7 @@ pub struct Model { pub total: Decimal, pub bakery_id: Option, pub customer_id: Option, - pub placed_at: Option, + pub placed_at: NaiveDateTime, } #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] diff --git a/tests/crud/create_lineitem.rs b/tests/crud/create_lineitem.rs index d081dc5a..46411801 100644 --- a/tests/crud/create_lineitem.rs +++ b/tests/crud/create_lineitem.rs @@ -65,7 +65,7 @@ pub async fn test_create_lineitem(db: &DbConn) { let order_1 = order::ActiveModel { bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)), customer_id: Set(Some(customer_insert_res.last_insert_id as i32)), - placed_at: Set(Some(Utc::now().naive_utc())), + placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let order_insert_res: InsertResult = Order::insert(order_1) diff --git a/tests/crud/create_order.rs b/tests/crud/create_order.rs index 0d2f1903..5b0cd42d 100644 --- a/tests/crud/create_order.rs +++ b/tests/crud/create_order.rs @@ -66,7 +66,7 @@ pub async fn test_create_order(db: &DbConn) { bakery_id: Set(Some(bakery_insert_res.last_insert_id as i32)), customer_id: Set(Some(customer_insert_res.last_insert_id as i32)), total: Set(dec!(15.10)), - placed_at: Set(Some(Utc::now().naive_utc())), + placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let order_insert_res: InsertResult = Order::insert(order_1)