Skip to content

Commit 461aa92

Browse files
committed
Fix bug and update changelog
1 parent 9152d8c commit 461aa92

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

CHANGELOG.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,30 @@ fn get_arity_of<E: EntityTrait>() -> usize {
1717
}
1818
```
1919
* Associate `ActiveModel` to `EntityTrait` https://github.com/SeaQL/sea-orm/pull/2186
20+
* [sea-orm-macros] Added `rename_all` attribute to `DeriveEntityModel` & `DeriveActiveEnum` https://github.com/SeaQL/sea-orm/pull/2170
21+
```rust
22+
#[derive(DeriveEntityModel)]
23+
#[sea_orm(table_name = "user", rename_all = "camelCase")]
24+
pub struct Model {
25+
#[sea_orm(primary_key)]
26+
id: i32,
27+
first_name: String, // firstName
28+
#[sea_orm(column_name = "lAsTnAmE")]
29+
last_name: String, // lAsTnAmE
30+
}
2031

32+
#[derive(EnumIter, DeriveActiveEnum)]
33+
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "camelCase")]
34+
pub enum TestEnum {
35+
DefaultVariant, // defaultVariant
36+
#[sea_orm(rename = "kebab-case")]
37+
VariantKebabCase, // variant-kebab-case
38+
#[sea_orm(rename = "snake_case")]
39+
VariantSnakeCase, // variant_snake_case
40+
#[sea_orm(string_value = "CuStOmStRiNgVaLuE")]
41+
CustomStringValue, // CuStOmStRiNgVaLuE
42+
}
43+
```
2144
### Enhancements
2245

2346
* Added `ActiveValue::set_if_not_equals()` https://github.com/SeaQL/sea-orm/pull/2194
@@ -562,7 +585,7 @@ assert!(matches!(res, Ok(TryInsertResult::Conflicted)));
562585

563586
* Fixed `DeriveActiveEnum` throwing errors because `string_value` consists non-UAX#31 compliant characters https://github.com/SeaQL/sea-orm/pull/1374
564587
```rust
565-
#[derive(DeriveActiveEnum)]
588+
#[derive(EnumIter, DeriveActiveEnum)]
566589
#[sea_orm(rs_type = "String", db_type = "String(None)")]
567590
pub enum StringValue {
568591
#[sea_orm(string_value = "")]

sea-orm-macros/src/derives/active_enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl ActiveEnum {
115115
// to be considered unknown attribute parameter
116116
meta.value()?.parse::<LitStr>()?;
117117
} else if meta.path.is_ident("rename") {
118+
is_string = true;
118119
rename_rule = Some((&meta).try_into()?);
119120
} else {
120121
return Err(meta.error(format!(
@@ -228,7 +229,6 @@ impl ActiveEnum {
228229
quote! { #num_value }
229230
} else if let Some(rename_rule) = variant.rename.or(*rename_all) {
230231
let variant_ident = variant.ident.convert_case(Some(rename_rule));
231-
232232
quote! { #variant_ident }
233233
} else {
234234
quote_spanned! {

sea-orm-macros/tests/derive_active_enum_test.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sea_orm::ActiveEnum;
1+
use sea_orm::{entity::prelude::StringLen, ActiveEnum};
22
use sea_orm_macros::{DeriveActiveEnum, EnumIter};
33

44
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
@@ -34,6 +34,18 @@ enum TestEnum {
3434
CustomStringValue,
3535
}
3636

37+
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
38+
#[sea_orm(
39+
rs_type = "String",
40+
db_type = "String(StringLen::None)",
41+
rename_all = "snake_case"
42+
)]
43+
pub enum TestEnum2 {
44+
HelloWorld,
45+
#[sea_orm(rename = "camelCase")]
46+
HelloWorldTwo,
47+
}
48+
3749
#[test]
3850
fn derive_active_enum_value() {
3951
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
@@ -107,3 +119,9 @@ fn derive_active_enum_from_value() {
107119
Ok(TestEnum::CustomStringValue)
108120
);
109121
}
122+
123+
#[test]
124+
fn derive_active_enum_value_2() {
125+
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
126+
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");
127+
}

0 commit comments

Comments
 (0)