Просмотр исходного кода

✨ feat(contracts-renew): 添加合同续期与合同的关联关系

- 在hetong-renew.entity.ts中添加@JoinColumn装饰器,明确关联字段contract_id
- 在CRUD路由配置中添加relations: ['contract'],支持查询时关联合同信息
yourname 8 месяцев назад
Родитель
Сommit
3df058c9eb

+ 1 - 0
src/server/api/contracts-renew/index.ts

@@ -10,6 +10,7 @@ const hetongRenewRoutes = createCrudRoutes({
   getSchema: HetongRenewSchema,
   listSchema: HetongRenewSchema,
   searchFields: ['contractId', 'state', 'auditStatus'],
+  relations: ['contract'],
   middleware: [authMiddleware]
 });
 

+ 3 - 2
src/server/modules/contracts/hetong-renew.entity.ts

@@ -1,4 +1,4 @@
-import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey, ManyToOne } from 'typeorm';
+import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey, ManyToOne, JoinColumn } from 'typeorm';
 import { Client } from '../clients/client.entity';
 
 import { z } from '@hono/zod-openapi';
@@ -10,9 +10,10 @@ export class HetongRenew {
   id!: number;
 
   @Column({ name: 'contract_id', type: 'int', unsigned: true })
-  @ForeignKey(() => Hetong)
   contractId!: number;
+
   @ManyToOne(() => Hetong, hetong => hetong.renews)
+  @JoinColumn({ name: 'contract_id' })
   contract!: Hetong;
 
   @Column({ name: 'amount', type: 'varchar', length: 50, nullable: true })