我有带出席记录选项子服务的设置模块。我正在调用路由,从那里我调用其中包含的对象(与 Postgress 数据库交互并将数据保存在 Postgress 数据库中)settingsController
settingsService
AttendanceRecordOptionsService
AttendanceRecordOptionsRepository
文件夹结构:
设置模块
Module({
imports: [],
controllers: [SettingsController],
providers: [
{
provide: getRepositoryToken(AttendanceRecordOptions),
inject: [TENANT_CONNECTION],
scope: Scope.REQUEST,
useFactory: connection => connection.getRepository(AttendanceRecordOptions),
},
SettingsService,
AttendanceRecordOptionsService,
],
exports: [SettingsService],
})
这运行良好,没有错误,但是当我调用任何有关AttendanceRecordOptions的路线时,它给了我错误No repository for "AttendanceRecordOptions" was found. Looks like this entity is not registered in current "tenant2" connection?
当我在迁移文件中创建具有如下硬编码值的对象并保存它时,所有路由都开始工作,我可以使用控制器中的路由存储数据。
const attendance_record_options_repository = queryRunner.manager.getRepository(AttendanceRecordOptions)
const aro = new AttendanceRecordOptions()
aro.name = 'name'
aro.prefix = 'pre'
aro.shortName = 'short'
aro.description = ' description'
aro.type = 'bool'
await attendance_record_options_repository.save(aro)
为什么我会从 NestJS 和 TypeORM 得到这种行为?