postgresql - 使用 NestJS、TypeORM 和 PostgreSQL 创建实体时出错
问题描述
我在 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 它可以工作,但是当我尝试创建新患者时会发生错误
解决方案
我设法解决了这个问题,实际上问题不在代码中,而是在我发送的有效负载中,我发送了一个带有 MedicalRecord 字段的有效负载,这产生了错误,当我从有效负载中删除它时,事情开始工作了再次=)
推荐阅读
- jmeter - 如何修复 JMeter ArrayIndexOutOfBoundsException?
- ios - 抓取google文档翻译目标c
- java - 无法遍历 JSON 数组
- jsp - Firefox 调试器中的 SOURCEsourceXXX 文件是什么,它在哪里?
- vb.net - 如何使用 VB.NET 连接 VFP 数据库
- html - 删除图像 HTML 表中不需要的填充/边距/边框
- makefile - 'make' 命令运行 ./configure
- django - Django REST Framework 序列化多个相关的外键
- javascript - 随机数组更新
- c# - MVC 如何将模型发送到动作链接?