【问题标题】:Error creating entity with NestJS, TypeORM and PostgreSQL使用 NestJS、TypeORM 和 PostgreSQL 创建实体时出错
【发布时间】:2021-11-27 03:25:27
【问题描述】:

我正在 NestJS、TypeORM 和 Postgres 中创建一个项目,用于在大学工作,但在特定情况下,TypeORM 给我以下错误relatedEntities.forEach is not a function

这是患者实体

@Entity()
@Unique(['cpf'])
export class Patient extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: false, type: 'varchar', length: 100 })
  name: string;

  @Column({ nullable: false, type: 'varchar', length: 255, select: false })
  password: string;

  @Column({ nullable: false, type: 'char', length: 11 })
  cpf: string;

  @OneToMany(() => MedicalRecord, medicalRecord => medicalRecord.patient)
  medicalRecord: MedicalRecord[];
}

这是病历


@Entity()
export class MedicalRecord extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: true, type: 'text' })
  diseaseHistory: string;

  @Column({ nullable: true, type: 'text' })
  medicines: string;

  @ManyToOne(() => Patient, patient => patient.medicalRecord)
  patient: Patient;
}

如果我创建或列出 MedicalRecords 它可以工作,但是当我尝试创建新患者时会发生错误

【问题讨论】:

标签: postgresql nestjs typeorm


【解决方案1】:

我设法解决了这个问题,实际上问题不在代码中,而是在我发送的有效负载中,我发送了一个带有 medicalRecord 字段的有效负载,当我从有效负载中删除它时,这会产生错误事情又开始工作了=)

【讨论】:

    猜你喜欢
    • 2019-11-13
    • 2020-12-29
    • 2020-09-18
    • 2020-01-03
    • 2020-01-25
    • 2021-08-21
    • 1970-01-01
    • 2022-01-03
    • 2021-06-05
    相关资源
    最近更新 更多