【发布时间】: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