我是Typeorm和nestjs的新手,但是我想知道是否有可能例如在建立关系时删除一对多的情况:
id | title | relationId
1 test 2
但是我想删除一个关系回到原始状态,如:
id | title | relationId
1 test [null]
然后,使用新的一对多关系来更新它,例如:
id | title | relationId
1 test 4
我不确定这是否真的可能
您可以null
在保存调用中将其作为关系传递,以从记录中清除该关系。
myRepository.save({ id: 1, title: 'test', relation: null })
请注意,您的列必须为可为空,否则TypeORM(和您的数据库)将强制relationId
具有的值。您可以通过以下方式进行设置:
@ManyToOne(() => Relation, (myEntity) => myEntity.relations)
relation: Relation | null
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句