【发布时间】:2022-01-02 14:41:40
【问题描述】:
我在测试 NestJS 服务时遇到了困难,该服务使用了一个只有一个关系的简单实体。然而,相关实体与许多其他实体相关,而这些其他实体又与其他实体相关。我不想导入所有实体并传递给TypeOrmModule.forRoot,如果不这样做,我会收到如下错误:
Entity metadata for Wallet#customer was not found.
对于每个尚未导入的实体。是否有可能以某种方式“模拟”这种关系?
测试:
const module: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(CONNECTION_OPTIONS),
TypeOrmModule.forFeature([WalletEntity, WalletTransactionEntity]),
],
providers: [WalletService],
}).compile();
实体
@Entity('wallet')
export class WalletEntity extends BaseEntity {
@Column()
customerId: string;
@OneToOne(() => CustomerEntity, (customer) => customer.wallet)
customer: CustomerEntity;
@OneToMany(() => WalletTransactionEntity, (transaction) => transaction.wallet)
transactions: WalletTransactionEntity[];
}
【问题讨论】: