diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index 0e2698c66..c67e8f58d 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -89,7 +89,7 @@ impl ActiveEnum { _ => return Err(Error::InputNotEnum), }; - let mut is_string = false; + let mut is_string = rename_all_rule.is_some(); let mut is_int = false; let mut variants = Vec::new(); @@ -129,7 +129,7 @@ impl ActiveEnum { .map_err(Error::Syn)?; } - if (is_string || rename_rule.is_some() || rename_all_rule.is_some()) && is_int { + if is_string && is_int { return Err(Error::TT(quote_spanned! { ident_span => compile_error!("All enum variants should specify the same `*_value` macro attribute, either `string_value` or `num_value` but not both"); })); diff --git a/sea-orm-macros/tests/derive_active_enum_test.rs b/sea-orm-macros/tests/derive_active_enum_test.rs index bfa694951..dd41d52c5 100644 --- a/sea-orm-macros/tests/derive_active_enum_test.rs +++ b/sea-orm-macros/tests/derive_active_enum_test.rs @@ -46,6 +46,16 @@ pub enum TestEnum2 { HelloWorldTwo, } +#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)] +#[sea_orm( + rs_type = "String", + db_type = "String(StringLen::None)", + rename_all = "snake_case" +)] +pub enum TestEnum3 { + HelloWorld, +} + #[test] fn derive_active_enum_value() { assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant"); @@ -124,4 +134,6 @@ fn derive_active_enum_from_value() { fn derive_active_enum_value_2() { assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world"); assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo"); + + assert_eq!(TestEnum3::HelloWorld.to_value(), "hello_world"); }