Reputation: 1430
Okay so I'm using TYPEORM_
prefixed environment variables to register TypeOrmModule
into my app. Then I'm loading entities using .forFeature()
like so:
@Module({
imports: [TypeOrmModule.forFeature([Foo])],
controllers: [FooController],
providers: [FooService],
exports: [TypeOrmModule],
})
export class FooModule {}
No matter whether I use forRoot()
or forRoot({ autoLoadEntities: true })
in AppModule
, I get RepositoryNotFoundError: No repository for "Foo" was found. Looks like this entity is not registered in current "default" connection?
error while working with the dev server. Any idea what's going on? My service looks like:
@Injectable()
export class FooService {
constructor(@InjectRepository(Foo) private readonly fooRepository: Repository<Foo>) {}
}
I tried the followings as single and/or combined, still didn't solve the issue.
@Entity()
decorator.@Entity('foo')
export class Foo {}
forRootAsync()
.@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: async () =>
Object.assign(await getConnectionOptions(), { autoLoadEntities: true }),
}),
FooModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
'default'
to forFeature()
.@Module({
imports: [TypeOrmModule.forFeature([Foo], 'default')],
controllers: [FooController],
providers: [FooService],
exports: [TypeOrmModule],
})
export class FooModule {}
entities
key in forRoot()
.@Module({
imports: [
TypeOrmModule.forRoot({ entities: [Foo] }),
FooModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Upvotes: 2
Views: 609
Reputation: 161
try to define connectionName inside getConnectionOptions
example:
@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: async () =>
Object.assign(await getConnectionOptions('default'), { autoLoadEntities: true }),
}),
FooModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Upvotes: 1