findingtheconcept / kindagoose

Typegoose integration with NestJS!
https://grapeoffjs.github.io/kindagoose/#/
GNU General Public License v3.0
27 stars 2 forks source link

Application crashes when the same schema is registered twice or more #114

Closed findingtheconcept closed 1 year ago

findingtheconcept commented 1 year ago

Description

Application crashes of the mongoose error when the same schema is registered twice or more.

Code:

@Module({
   imports: [
      KindagooseModule.forFeature([User, Company]),
   ],
   controllers: [UserController],
   providers: []
})
export class UserModule {}
@Module({
   imports: [
      KindagooseModule.forFeature([Company])
   ],
   controllers: [CompanyController],
   providers: []
})
export class CompanyModule {}

Error:

OverwriteModelError: Cannot overwrite `Company` model once compiled.
    at NativeConnection.Connection.model (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\mongoose\lib\connection.js:1214:13)
    at InstanceWrapper.metatype (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\kindagoose\src\utils\model-factory.ts:49:47)
    at Injector.instantiateClass (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\injector.js:354:55)
    at callback (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\injector.js:56:45)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Injector.resolveConstructorParams (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\injector.js:136:24)
    at Injector.loadInstance (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\injector.js:61:13)
    at Injector.loadProvider (C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\injector.js:88:9)
    at C:\Users\meebo\WebstormProjects\nest-demo\node_modules\@nestjs\core\injector\instance-loader.js:56:13
    at async Promise.all (index 3)
findingtheconcept commented 1 year ago

https://github.com/GrapeoffJS/kindagoose/releases/tag/1.3.2