فهرست منبع

✨ feat(contracts): 添加合同与续约记录的关联关系

- 在Hetong实体中添加OneToMany关联,建立与HetongRenew的一对多关系
- 在HetongRenew实体中添加ManyToOne关联,建立与Hetong的多对一关系
- 在HetongRenew实体中添加clientId字段和ManyToOne关联,建立与Client的关联关系
yourname 8 ماه پیش
والد
کامیت
28de1c97bd
2فایلهای تغییر یافته به همراه17 افزوده شده و 2 حذف شده
  1. 12 1
      src/server/modules/contracts/hetong-renew.entity.ts
  2. 5 1
      src/server/modules/contracts/hetong.entity.ts

+ 12 - 1
src/server/modules/contracts/hetong-renew.entity.ts

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

+ 5 - 1
src/server/modules/contracts/hetong.entity.ts

@@ -1,4 +1,5 @@
-import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey } from 'typeorm';
+import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey, OneToMany } from 'typeorm';
+import { HetongRenew } from './hetong-renew.entity';
 import { Client } from '../clients/client.entity';
 import { z } from '@hono/zod-openapi';
 
@@ -63,6 +64,9 @@ export class Hetong {
     onUpdate: 'CURRENT_TIMESTAMP' 
   })
   updatedAt!: Date;
+  
+  @OneToMany(() => HetongRenew, renew => renew.contract)
+  renews!: HetongRenew[];
 }
 
 export const HetongSchema = z.object({