gpt4 book ai didi

node.js - TypeORM 树级联移除

转载 作者:行者123 更新时间:2023-12-04 13:38:06 26 4
gpt4 key购买 nike

大家好,我在他们的文档中使用了 TypeORM 物化树:

https://github.com/typeorm/typeorm/blob/master/docs/tree-entities.md#materialized-path-aka-path-enumeration

现在我想删除一些根树 Node 并删除所有子 Node ,我使用这样的存储库:

await repository.remove(TreeNode);

但是由于外键限制,我无法删除,我通过了 cascade: true像这样:
Column({
length: 500,
default: '',
})
name: string

@TreeParent()
parent: Comment

@TreeChildren({
cascade: true,
})
children: Comment[]

但是没有任何效果???

最佳答案

我想我有一个类似的问题。
当我尝试删除父实体时,我遇到了这些错误。
在我使用 TreeRepostitory 的 findDescendants 之后,它将填充实体的子实体,删除工作正常。

update or delete on table "mytable" violates foreign key constraintKey (id)=(17) is still referenced from table "mytable"

let treeRepo = getManager().getTreeRepository(MyEntity);
await treeRepo.findDescendants(entity)
treeRepo.remove(entity)

关于node.js - TypeORM 树级联移除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60627340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com