【发布时间】:2020-11-14 23:23:09
【问题描述】:
在我的项目中,我有两个实体,自然主义者(用户)和评论实体 我创建它们之间的关系,如何在评论实体中保存reciever_id (joined cloumn)
这是我的评论实体
@Entity()
export class Comments extends BaseEntity {
@PrimaryGeneratedColumn()
id: string
@ManyToOne(
type => Naturalist,
naturalist => naturalist.comments
)
@JoinColumn({
name: 'naturalist_id',
})
naturalist: Naturalist
@Column({ nullable: true, default: '' })
text?: string
@Column({ nullable: true, default: '' })
sender_id?: string
}
博物学家(我的用户)实体
@Entity()
export class Naturalist extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
user_id: string
@OneToMany(
type => Comments,
comment => comment.naturalist
)
comments: Comments[]
}
DTO 包含
{
receiver_id: '2cc2f359-821c-4940-99ae-7386576d861b',
text: 'string',
id: 'e0464049-d1d9-474a-af5b-815805aa1c4b'
}
我想将receiver_id 保存到我的评论实体
【问题讨论】:
标签: node.js database postgresql nestjs typeorm