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

♻️ refactor(contracts): fix entity relationship mapping

- add missing JoinColumn decorator for client relationship
- move ForeignKey decorator to proper position for client_id column
- import JoinColumn from typeorm to establish correct database relationship
yourname 8 месяцев назад
Родитель
Сommit
b33fc911ee
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      src/server/modules/contracts/hetong.entity.ts

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

@@ -1,4 +1,4 @@
-import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey, OneToMany, ManyToOne } from 'typeorm';
+import { Entity, PrimaryGeneratedColumn, Column, Index, ForeignKey, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
 import { HetongRenew } from './hetong-renew.entity';
 import { HetongRenew } from './hetong-renew.entity';
 import { Client } from '../clients/client.entity';
 import { Client } from '../clients/client.entity';
 import { z } from '@hono/zod-openapi';
 import { z } from '@hono/zod-openapi';
@@ -15,9 +15,10 @@ export class Hetong {
   userId!: string;
   userId!: string;
 
 
   @Column({ name: 'client_id', type: 'int', unsigned: true })
   @Column({ name: 'client_id', type: 'int', unsigned: true })
-  @ForeignKey(() => Client)
   clientId!: number;
   clientId!: number;
+
   @ManyToOne(() => Client)
   @ManyToOne(() => Client)
+  @JoinColumn({ name: 'client_id' })
   client!: Client;
   client!: Client;
 
 
   @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })
   @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })