Skip to content

Commit 26ccabc

Browse files
authored
docs: add @nestjs/typeorm issue 86 solution in sql.md
1 parent 2bf46e6 commit 26ccabc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

content/techniques/sql.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,21 @@ export class AppModule {}
576576

577577
> warning **Notice** If you don't set the `name` for a connection, its name is set to `default`. Please note that you shouldn't have multiple connections without a name, or with the same name, otherwise they will get overridden.
578578
579+
> warning **Notice** If you are using `TypeOrmModule.forRootAsync`, you have to set connection name outside `useFactory`. For example:
580+
> ```typescript
581+
> TypeOrmModule.forRootAsync({
582+
> name: 'albumsConnection',
583+
> useFactory: (config: ConfigService) =>
584+
> ({
585+
> ...config.get('db'),
586+
> host: 'album_db_host',
587+
> entities: [Album],
588+
> } as TypeOrmModuleOptions),
589+
> inject: [ConfigService],
590+
> }),
591+
> ```
592+
> [@nestjs/typeorm issue](https://github.com/nestjs/typeorm/issues/86)
593+
579594
At this point, you have `User` and `Album` entities registered with their own connection. With this setup, you have to tell the `TypeOrmModule.forFeature()` method and the `@InjectRepository()` decorator which connection should be used. If you do not pass any connection name, the `default` connection is used.
580595
581596
```typescript

0 commit comments

Comments
 (0)