Skip to content

Commit

Permalink
Merge branch 'lukasschlueter-master' into fix_duplicate_active_enum_i…
Browse files Browse the repository at this point in the history
…mports
  • Loading branch information
onefifth committed Nov 1, 2023
2 parents 06c6327 + f9020c5 commit 34f212a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,23 @@ impl EntityWriter {
entity
.columns
.iter()
.fold(TokenStream::new(), |mut ts, col| {
if let sea_query::ColumnType::Enum { name, .. } = col.get_inner_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;
}]);
}
ts
})
.fold(
(TokenStream::new(), Vec::new()),
|(mut ts, mut enums), col| {
if let sea_query::ColumnType::Enum { name, .. } = col.get_inner_col_type() {
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, enums)
},
)
.0
}

pub fn gen_model_struct(
Expand Down

0 comments on commit 34f212a

Please sign in to comment.