Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BeneCollyridam opened this issue Sep 30, 2021 · 4 comments · Fixed by #224
Closed

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

BeneCollyridam opened this issue Sep 30, 2021 · 4 comments · Fixed by #224
Assignees

Comments

@BeneCollyridam
Copy link

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!

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 30, 2021

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 tyt2y3 closed this as completed Sep 30, 2021
@tyt2y3 tyt2y3 reopened this Sep 30, 2021
@tyt2y3
Copy link
Member

tyt2y3 commented Oct 1, 2021

0.2.4

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 4, 2021

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
Copy link
Member

tyt2y3 commented Oct 9, 2021

0.2.6

arpancodes pushed a commit to arpancodes/sea-orm that referenced this issue Apr 8, 2022
…ix SeaQL#217 (SeaQL#219)

* Add failing tests

* Fix tests: add tbl_ prefix to Table wildcard method

* Fix typo in tests

* Make tests pass

* fix docs tests

* rename wildcard to asterisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants