Fix bug and update changelog
This commit is contained in:
parent
9152d8cac9
commit
461aa925f6
25
CHANGELOG.md
25
CHANGELOG.md
@ -17,7 +17,30 @@ fn get_arity_of<E: EntityTrait>() -> usize {
|
||||
}
|
||||
```
|
||||
* Associate `ActiveModel` to `EntityTrait` https://github.com/SeaQL/sea-orm/pull/2186
|
||||
* [sea-orm-macros] Added `rename_all` attribute to `DeriveEntityModel` & `DeriveActiveEnum` https://github.com/SeaQL/sea-orm/pull/2170
|
||||
```rust
|
||||
#[derive(DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "user", rename_all = "camelCase")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
id: i32,
|
||||
first_name: String, // firstName
|
||||
#[sea_orm(column_name = "lAsTnAmE")]
|
||||
last_name: String, // lAsTnAmE
|
||||
}
|
||||
|
||||
#[derive(EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "camelCase")]
|
||||
pub enum TestEnum {
|
||||
DefaultVariant, // defaultVariant
|
||||
#[sea_orm(rename = "kebab-case")]
|
||||
VariantKebabCase, // variant-kebab-case
|
||||
#[sea_orm(rename = "snake_case")]
|
||||
VariantSnakeCase, // variant_snake_case
|
||||
#[sea_orm(string_value = "CuStOmStRiNgVaLuE")]
|
||||
CustomStringValue, // CuStOmStRiNgVaLuE
|
||||
}
|
||||
```
|
||||
### Enhancements
|
||||
|
||||
* Added `ActiveValue::set_if_not_equals()` https://github.com/SeaQL/sea-orm/pull/2194
|
||||
@ -562,7 +585,7 @@ assert!(matches!(res, Ok(TryInsertResult::Conflicted)));
|
||||
|
||||
* Fixed `DeriveActiveEnum` throwing errors because `string_value` consists non-UAX#31 compliant characters https://github.com/SeaQL/sea-orm/pull/1374
|
||||
```rust
|
||||
#[derive(DeriveActiveEnum)]
|
||||
#[derive(EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "String(None)")]
|
||||
pub enum StringValue {
|
||||
#[sea_orm(string_value = "")]
|
||||
|
@ -115,6 +115,7 @@ impl ActiveEnum {
|
||||
// to be considered unknown attribute parameter
|
||||
meta.value()?.parse::<LitStr>()?;
|
||||
} else if meta.path.is_ident("rename") {
|
||||
is_string = true;
|
||||
rename_rule = Some((&meta).try_into()?);
|
||||
} else {
|
||||
return Err(meta.error(format!(
|
||||
@ -228,7 +229,6 @@ impl ActiveEnum {
|
||||
quote! { #num_value }
|
||||
} else if let Some(rename_rule) = variant.rename.or(*rename_all) {
|
||||
let variant_ident = variant.ident.convert_case(Some(rename_rule));
|
||||
|
||||
quote! { #variant_ident }
|
||||
} else {
|
||||
quote_spanned! {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use sea_orm::ActiveEnum;
|
||||
use sea_orm::{entity::prelude::StringLen, ActiveEnum};
|
||||
use sea_orm_macros::{DeriveActiveEnum, EnumIter};
|
||||
|
||||
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
|
||||
@ -34,6 +34,18 @@ enum TestEnum {
|
||||
CustomStringValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
|
||||
#[sea_orm(
|
||||
rs_type = "String",
|
||||
db_type = "String(StringLen::None)",
|
||||
rename_all = "snake_case"
|
||||
)]
|
||||
pub enum TestEnum2 {
|
||||
HelloWorld,
|
||||
#[sea_orm(rename = "camelCase")]
|
||||
HelloWorldTwo,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_active_enum_value() {
|
||||
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
|
||||
@ -107,3 +119,9 @@ fn derive_active_enum_from_value() {
|
||||
Ok(TestEnum::CustomStringValue)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_active_enum_value_2() {
|
||||
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
|
||||
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user