File tree 1 file changed +38
-2
lines changed
1 file changed +38
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { DynamicModule , Module } from '@nestjs/common' ;
2
- import { Connection , ConnectionOptions , EntitySchema } from 'typeorm' ;
2
+ import {
3
+ AbstractRepository ,
4
+ Connection ,
5
+ ConnectionOptions ,
6
+ EntitySchema ,
7
+ getMetadataArgsStorage ,
8
+ Repository ,
9
+ } from 'typeorm' ;
3
10
import { EntitiesMetadataStorage } from './entities-metadata.storage' ;
4
11
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type' ;
5
12
import {
@@ -27,7 +34,36 @@ export class TypeOrmModule {
27
34
| string = DEFAULT_CONNECTION_NAME ,
28
35
) : DynamicModule {
29
36
const providers = createTypeOrmProviders ( entities , connection ) ;
30
- EntitiesMetadataStorage . addEntitiesByConnection ( connection , entities ) ;
37
+ let repEntities = [ ] ;
38
+ for ( let entity of entities ) {
39
+ if (
40
+ entity instanceof Function &&
41
+ ( entity . prototype instanceof Repository ||
42
+ entity . prototype instanceof AbstractRepository )
43
+ ) {
44
+ const entityRepositoryMetadataArgs = getMetadataArgsStorage ( ) . entityRepositories . find (
45
+ ( repository ) => {
46
+ return (
47
+ repository . target ===
48
+ ( entity instanceof Function
49
+ ? entity
50
+ : ( entity as any ) . constructor )
51
+ ) ;
52
+ } ,
53
+ ) ;
54
+ if ( entityRepositoryMetadataArgs ) {
55
+ if (
56
+ entities . indexOf ( < any > entityRepositoryMetadataArgs . entity ) === - 1
57
+ ) {
58
+ repEntities . push ( entityRepositoryMetadataArgs . entity ) ;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ EntitiesMetadataStorage . addEntitiesByConnection ( connection , [
64
+ ...entities ,
65
+ ...repEntities ,
66
+ ] ) ;
31
67
return {
32
68
module : TypeOrmModule ,
33
69
providers : providers ,
You can’t perform that action at this time.
0 commit comments