Skip to content

Commit

Permalink
fix: Only generate use statements once per enum
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasschlueter committed Jun 11, 2023
1 parent 1431d80 commit 7cf3195
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7cf3195

Please sign in to comment.