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

Public exports of generated models can be improved #997

Open
JonasCir opened this issue Nov 19, 2024 · 0 comments
Open

Public exports of generated models can be improved #997

JonasCir opened this issue Nov 19, 2024 · 0 comments
Milestone

Comments

@JonasCir
Copy link

Description

When generating a model, the created file (e.g., src/models/persons.rs) is missing public reexports for ActiveModel and Model. Only Entity is publicly exported.

The default src/models/users.rs file, however, reexports everything through pub use super::_entities::users::{self, ActiveModel, Entity, Model};. This allows convenient (and clean) usage of these types in tests (see import section of tests/models/users.rs.

Tests for newly generated models (e.g., tests/models/persons.rs) need to use the full path to access the corresponding ActiveModel.

I do not consider this a bug - as the user can easily work around it - but unifying this would streamline the developer experience.

To Reproduce

  1. Generate a new SaaS project
  2. cargo loco generate scaffold persons uuid:uuid first_name:string! last_name:string! --api
  3. Import section of tests/models/persons.rs and src/controllers/persons.rs is not ideal.

Expected Behavior

src/models/persons.rs should look like this:

pub use super::_entities::persons::{ActiveModel, Entity as Persons, Model};
use sea_orm::entity::prelude::*;


impl ActiveModelBehavior for ActiveModel {
    // extend activemodel below (keep comment for generators)
}

tests/models/persons then can use a clean and simple import like use foobar::models::persons::{self, Persons};

Environment:

  • loco-cli 0.12.0
  • rustc 1.82.0 (f6e511eec 2024-10-15) with target stable-x86_64-unknown-linux-gnu (default)

Additional Context

None

@kaplanelad kaplanelad added this to the 0.14.0 milestone Nov 25, 2024
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

No branches or pull requests

2 participants