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

Add support for autoLoadEntities #8

Closed
chasevida opened this issue Sep 22, 2020 · 3 comments
Closed

Add support for autoLoadEntities #8

chasevida opened this issue Sep 22, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@chasevida
Copy link

Describe the bug
First off, great project - I'm really grateful for all the work you've put in on this.

The issue I'm running into with this module is when it's run within a nest monorepo the glob patterns for entity discovery does not work (for js or ts files). This appears to be a known issue also faced with TypeORM where they have added an autoLoadEntities prop in order to resolve it.

Not importing entities in manually results in a No entities were discovered error on startup.

I can (and am presently) importing files manually but this seems a bit unintuitive given that now I have to expose these from scoped libraries within the larger nest monorepo.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new nest project as a monorepo
  2. Install and configure @mikro-orm/nestjs as a library module
  3. Configure an entity or two and use the glob patter in the Mikro ORM config
  4. Run the application

Expected behavior
All entities should be discovered based on their glob and load within Mikro ORM.

Additional context
I'd be happy to do this another way if I can scope a Mikro ORM instance per library module if that's better but I'm unsure if Mikro ORM sets itself up globally and wouldn't allow this.

Versions

Dependency Version
node 12.x
@nestjs/core 7.0.0
@mikro-orm/core 4.0.3
@mikro-orm/nestjs 4.0.0
@chasevida chasevida added the bug Something isn't working label Sep 22, 2020
@B4nan
Copy link
Member

B4nan commented Sep 22, 2020

I thought that nest monorepo mode = using webpack. And webpack = you cannot use folder based discovery at all.

@chasevida
Copy link
Author

Yeah that's sounds right (first 48 hours into nest/mikro-orm). However, I wasn't sure how TypeORM was able to do this and wondered if I was missing something here. I might go through the docs again to see if there's a way I can register entities locally (in their seperate module scopes) before they are instantiated in root.

@B4nan
Copy link
Member

B4nan commented Sep 23, 2020

Looking at the autoLoadEntities, sure we can do the same here, it's just not supported currently.

edit: there is one issue tho - in MikroORM it is required to discover also the base entities, but you cannot use those in forFeature. so you will still need to provide list of base entities in the forRoot, rest can be autoloaded.

edit2: this also won't work for CLI, you will still need full CLI config including all the entities (but for CLI you can use globs, as there won't be any webpack used).

@B4nan B4nan changed the title MikroOrmModule.forRoot entities glob patterns unworkable in nestjs monorepo Add support for autoLoadEntities Sep 23, 2020
@B4nan B4nan added enhancement New feature or request and removed bug Something isn't working labels Sep 23, 2020
@B4nan B4nan closed this as completed in ceaf16e Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants