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

sea-orm-cli: Entity generation fails if column name is a reserved keyword

Open BeneCollyridam opened this issue 5 years ago • 4 comments

Hello,

I am very excited by this project, and I think the work you're doing is amazing.

I encountered a problem, when I was trying to use sea-orm-cli to generate entities. I got an error as one of the columns in my database was named type which is a reserved keyword. rustc suggest fixing it by writing r#type instead in the generated code.

Keep up the great work!

BeneCollyridam avatar Sep 30 '21 13:09 BeneCollyridam

Hi there, welcome!

It has also been discussed in #82 .

Basically the preliminary work #209 has already been merged, and will be released soon (like this week).

But it'd take some time for us to fix the codegen indeed.

Thank you for your support!

tyt2y3 avatar Sep 30 '21 14:09 tyt2y3

0.2.4

tyt2y3 avatar Oct 01 '21 04:10 tyt2y3

Example included in https://www.sea-ql.org/SeaORM/blog#rename-column-name--column-enum-variant

mod my_entity {
    use sea_orm::entity::prelude::*;

    #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
    #[sea_orm(table_name = "my_entity")]
    pub struct Model {
        #[sea_orm(primary_key, enum_name = "IdentityColumn", column_name = "id")]
        pub id: i32,
        #[sea_orm(column_name = "type")]
        pub type_: String,
    }

    //...
}

assert_eq!(my_entity::Column::IdentityColumn.to_string().as_str(), "id");
assert_eq!(my_entity::Column::Type.to_string().as_str(), "type");

tyt2y3 avatar Oct 04 '21 01:10 tyt2y3

0.2.6

tyt2y3 avatar Oct 09 '21 15:10 tyt2y3