sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Allow Defaulting `string_value` For ActiveEnum Based On Renaming Rules On Variants

Open anshap1719 opened this issue 1 year ago • 1 comments

Discussed in https://github.com/SeaQL/sea-orm/discussions/2125

Originally posted by wyatt-herkamp March 1, 2024 Take the following enum. I think we should automatically use the Variant name if the string_value is not provided.

#[derive(DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "Interval")]
pub enum Intervals {
    #[sea_orm(string_value = "Weekly")]
    Weekly,
    #[sea_orm(string_value = "BIWeekly")]
    BIWeekly,
    #[sea_orm(string_value = "Monthly")]
    Monthly,
    #[sea_orm(string_value = "Quarterly")]
    Quarterly,
    #[sea_orm(string_value = "Yearly")]
    Yearly,
}

This would allow people to do

#[derive(DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "Interval")]
pub enum Intervals {
    Weekly,
    BIWeekly,
    Monthly,
    Quarterly,
    Yearly,
}

And get the same result. I would be happy to make a PR if the developers of the project is Ok with this feature.

anshap1719 avatar Mar 16 '24 07:03 anshap1719

@tyt2y3 While I was working on this, it made sense to also have this for model structs, so i decided to add that in (will be pushing later today). Let me know if there are any arguments against that.

anshap1719 avatar Mar 22 '24 14:03 anshap1719