Skip to content

Commit 026a183

Browse files
committed
refactor(typeorm): Update getRepositoryToken provider generation
This change will make Repository generation use getEntityManagerToken instead of getConnectionToken closes #1819
1 parent b4e09dc commit 026a183

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/typeorm.providers.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Provider } from '@nestjs/common';
2-
import { DataSource, DataSourceOptions, getMetadataArgsStorage } from 'typeorm';
3-
import { getDataSourceToken, getRepositoryToken } from './common/typeorm.utils';
2+
import { DataSource, DataSourceOptions, EntityManager, getMetadataArgsStorage } from 'typeorm';
3+
import { getDataSourceToken, getEntityManagerToken, getRepositoryToken } from './common/typeorm.utils';
44
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type';
55

66
export function createTypeOrmProviders(
@@ -9,16 +9,16 @@ export function createTypeOrmProviders(
99
): Provider[] {
1010
return (entities || []).map((entity) => ({
1111
provide: getRepositoryToken(entity, dataSource),
12-
useFactory: (dataSource: DataSource) => {
13-
const enitityMetadata = dataSource.entityMetadatas.find((meta) => meta.target === entity)
12+
useFactory: (entityManager: EntityManager) => {
13+
const enitityMetadata = entityManager.connection.entityMetadatas.find((meta) => meta.target === entity)
1414
const isTreeEntity = typeof enitityMetadata?.treeType !== 'undefined'
15-
return isTreeEntity
16-
? dataSource.getTreeRepository(entity)
17-
: dataSource.options.type === 'mongodb'
18-
? dataSource.getMongoRepository(entity)
19-
: dataSource.getRepository(entity);
15+
return isTreeEntity
16+
? entityManager.getTreeRepository(entity)
17+
: entityManager.connection.options.type === 'mongodb'
18+
? entityManager.getMongoRepository(entity)
19+
: entityManager.getRepository(entity);
2020
},
21-
inject: [getDataSourceToken(dataSource)],
21+
inject: [getEntityManagerToken(dataSource)],
2222
/**
2323
* Extra property to workaround dynamic modules serialisation issue
2424
* that occurs when "TypeOrm#forFeature()" method is called with the same number

0 commit comments

Comments
 (0)