Lets lay ive got a root module like:
@Module({
imports: [MikroOrmModule.forRoot({
metadataProvider: TsMorphMetadataProvider,
entities: ['dist/**/*.entity.js'],
entitiesTs: ['src/**/*.entity.ts'],
type: 'postgresql' as const,
baseDir: path.resolve(__dirname, '..'),
...
})],
})
export class AppModule {}
With this setting I can inject EntityManager
, but @InjectRepository(User)
is not finding the provider.
@Injectable()
export class SomeService {
constructor(@InjectRepository(user) userRepository: EntityRepository<User>) {}
}
If I also insert MikroOrmModule.forFeature([User])
into the root module it does not work. If I move the entity into a submodule and use .forFeature
there (just like the example in the docs say) it works.
Is it possible to have @InjectRepository()
working without the need for sub modules and manual referencing? Since Im already finding the entities with blobs, manually referencing them again seems to defeat the purpose of the blob pattern.
The blob pattern is to tell the ORM what all entities there are and what to have connections for. The
forFeature
pattern is to register all of the entities with Nest so that Nest can create injection tokens for them. As they are separate processes, there isn't a way to use only one of them. Unless theMikroOrmModule
implements something like Nest'sautoLoadEntities
(on TypeOrmModule and SequelizeModule), there won't be a way to use only the globs.