From 7cf319556d17c57cb95a91b96b573468a310bc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schl=C3=BCter=20Lukas?= Date: Sun, 11 Jun 2023 19:09:58 +0200 Subject: [PATCH] fix: Only generate `use` statements once per enum --- sea-orm-codegen/src/entity/writer.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 36da98910..42597fce3 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -460,15 +460,18 @@ impl EntityWriter { entity .columns .iter() - .fold(TokenStream::new(), |mut ts, col| { + .fold((TokenStream::new(), Vec::new()), |(mut ts, mut enums), col| { if let sea_query::ColumnType::Enum { name, .. } = &col.col_type { - let enum_name = format_ident!("{}", name.to_string().to_upper_camel_case()); - ts.extend([quote! { - use super::sea_orm_active_enums::#enum_name; - }]); + if !enums.contains(&name) { + enums.push(name); + let enum_name = format_ident!("{}", name.to_string().to_upper_camel_case()); + ts.extend([quote! { + use super::sea_orm_active_enums::#enum_name; + }]); + } } - ts - }) + (ts, enums) + }).0 } pub fn gen_model_struct(