小编rca*_*tte的帖子

NestJS - TypeORM - ManyToOne 实体未定义

我正在尝试链接到实体Child&Client

所以我创建了 2 个实体:

// src/children/child.entity.ts

@Entity()
export class Child extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  firstname: string;

  @Column()
  lastname: string;

  @ManyToOne(type => Client, client => client.children, { eager: false })
  client: Client

  @Column()
  clientId: number;
}
Run Code Online (Sandbox Code Playgroud)

// src/clients/client.entity.ts

@Entity()
export class Client extends BaseEntity {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  firstname: string;

  @Column()
  lastname: string;

  @OneToMany(type => Child, child => child.client, { eager: true })
  children: Child[];

}
Run Code Online (Sandbox Code Playgroud)

我能够创建 a client& a child。当我得到一个时 …

entity many-to-one typescript typeorm nestjs

6
推荐指数
1
解决办法
9896
查看次数

标签 统计

entity ×1

many-to-one ×1

nestjs ×1

typeorm ×1

typescript ×1