From 04b6c9ad13fb9f38d445bba3ffd6c11bc753d0a8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 3 Sep 2024 10:33:37 +0200 Subject: [PATCH] Use input ident instead of associated type projections in ActiveModel derive --- sea-orm-macros/src/derives/active_model.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sea-orm-macros/src/derives/active_model.rs b/sea-orm-macros/src/derives/active_model.rs index 60cac7e4d..2ad8348a4 100644 --- a/sea-orm-macros/src/derives/active_model.rs +++ b/sea-orm-macros/src/derives/active_model.rs @@ -22,8 +22,8 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result syn::Result) -> syn::Result { +fn derive_active_model(ident: &Ident, all_fields: IntoIter) -> syn::Result { let fields = all_fields.filter(field_not_ignored); let field: Vec = fields.clone().map(format_field_ident).collect(); @@ -87,8 +87,8 @@ fn derive_active_model(all_fields: IntoIter) -> syn::Result } #[automatically_derived] - impl std::convert::From<::Model> for ActiveModel { - fn from(m: ::Model) -> Self { + impl std::convert::From<#ident> for ActiveModel { + fn from(m: #ident) -> Self { Self { #(#field: sea_orm::ActiveValue::unchanged(m.#field)),* } @@ -96,7 +96,7 @@ fn derive_active_model(all_fields: IntoIter) -> syn::Result } #[automatically_derived] - impl sea_orm::IntoActiveModel for ::Model { + impl sea_orm::IntoActiveModel for #ident { fn into_active_model(self) -> ActiveModel { self.into() } @@ -161,7 +161,7 @@ fn derive_active_model(all_fields: IntoIter) -> syn::Result )) } -fn derive_into_model(model_fields: IntoIter) -> syn::Result { +fn derive_into_model(ident: &Ident, model_fields: IntoIter) -> syn::Result { let active_model_fields = model_fields.clone().filter(field_not_ignored); let active_model_field: Vec = active_model_fields @@ -192,7 +192,7 @@ fn derive_into_model(model_fields: IntoIter) -> syn::Result Ok(quote!( #[automatically_derived] - impl std::convert::TryFrom for ::Model { + impl std::convert::TryFrom for #ident { type Error = sea_orm::DbErr; fn try_from(a: ActiveModel) -> Result { #(if matches!(a.#active_model_field, sea_orm::ActiveValue::NotSet) { @@ -207,8 +207,8 @@ fn derive_into_model(model_fields: IntoIter) -> syn::Result } #[automatically_derived] - impl sea_orm::TryIntoModel<::Model> for ActiveModel { - fn try_into_model(self) -> Result<::Model, sea_orm::DbErr> { + impl sea_orm::TryIntoModel<#ident> for ActiveModel { + fn try_into_model(self) -> Result<#ident, sea_orm::DbErr> { self.try_into() } }