【发布时间】:2022-09-23 17:14:35
【问题描述】:
在一个项目中,我需要两个不同实体之间的可为空的 ManyToOne - OneToMany 关系。现在我这样解决了:
L1Log 实体(ManyToOne 端)
@Entity()
export class L1Log extends BaseEntity {
@PrimaryGeneratedColumn(\'uuid\')
uuid: string
@Column({ type: \'varchar\', nullable: true })
dimonaCancelUuid?: string
@ManyToOne(() => DimonaCancel, dimonaCancel => dimonaCancel.l1Logs, { nullable: true })
@JoinColumn({ name: \'dimonaCancelUuid\' })
dimonaCancel?: DimonaCancel
}
DimonaCancel 实体(OneToMany 方)
@Entity()
export class DimonaCancel extends BaseEntity {
@PrimaryGeneratedColumn(\'uuid\')
uuid: string
@OneToMany(() => L1Log, l1Log => l1Log.dimonaCancel, { nullable: true })
l1Logs?: L1Log[]
}
我现在的问题是{可为空:真}选项中需要@OneToMany关系的一边,因为@OneToMany没有关系设置时会是一个空数组吗?
标签: node.js typeorm node.js-typeorm