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

Alphabetical order generating with sea-orm-cli #1223

Closed
frederikhors opened this issue Nov 12, 2022 · 4 comments · Fixed by #1229
Closed

Alphabetical order generating with sea-orm-cli #1223

frederikhors opened this issue Nov 12, 2022 · 4 comments · Fixed by #1229
Assignees

Comments

@frederikhors
Copy link
Contributor

Description

Using sea-orm-cli to generate entities I found out that the order of relations is random, not alphabetical.

Expected Behavior

I would like it to be alphabetical.

Actual Behavior

Sometimes it generates:

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::company::Entity",
        from = "Column::CompanyId",
        to = "super::company::Column::Id",
        on_update = "NoAction",
        on_delete = "NoAction"
    )]
    Company,
    #[sea_orm(has_many = "super::player::Entity")]
    Player,
    #[sea_orm(has_many = "super::team::Entity")]
    Team,
    #[sea_orm(has_many = "super::coach::Entity")]
    Coach,
}

Sometimes instead:

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::company::Entity",
        from = "Column::CompanyId",
        to = "super::company::Column::Id",
        on_update = "NoAction",
        on_delete = "NoAction"
    )]
    Company,
    #[sea_orm(has_many = "super::player::Entity")]
    Player,
    #[sea_orm(has_many = "super::coach::Entity")]
    Coach,
    #[sea_orm(has_many = "super::team::Entity")]
    Team,
}

Reproduces How Often

Yeah

Versions

sea-orm-cli 0.10.2
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 13, 2022

That's right. Non-determinism is sometimes annoying. I am mostly sure this is due to the pseudo-random nature of HashMap. The solution usually is to replace all HashMap with BTreeMap and so it will order naturally by the key.

@billy1624
Copy link
Member

Hey @frederikhors, thanks for the report!! I'll dig into it :)

@billy1624
Copy link
Member

Hey @frederikhors, please check #1229

@frederikhors
Copy link
Contributor Author

I think it should work. I cannot try it right now. Thanks!

@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants