如何删除包含所有子项的实体 [英] How to delete an entity including all children

查看:25
本文介绍了如何删除包含所有子项的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对数据存储区中的实体进行级联删除.我的意思是所有孩子和间接孩子也将被删除.我最初认为这将是默认行为,但不知何故它不是......

I would like to do a cascading delete on an entity in the datastore. By this I mean all children and indirect children will also be deleted. I initially assumed this would be default behavior but somehow it is not...

我的想法是这样的:

ndb.delete_multi(ndb.Model.query(ancestor=key).iter(keys_only = True))

但是Model应该是通配符,因为实体可以是几个类的父类...

But the Model should be a wildcard, because the entity can be the parent of several classes...

我还想在删除实体时删除 BlobKeyProperties.为此我在想关于:

I would also like to delete BlobKeyProperties when deleting an entity. For this I was thinking about:

@classmethod
  def _post_delete_hook(cls, key, future):
  # inform someone they have lost a friend

我也应该将其用于级联删除?

which I should maybe use for cascading delete as well?

推荐答案

对于 Kindless 祖先查询,从 查询类

For kindless ancestor queries create the query from the query class

ndb.delete_multi(ndb.Query(ancestor=key).iter(keys_only = True))

我不会对所有子实体使用级联删除.如果你有很多,那么它会慢得多(除非你想在一个任务中运行删除).

I wouldn't use the cascading delete for all child entities. If you have a lot then it will be much slower (unless you want to run the delete in a task).

这篇关于如何删除包含所有子项的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆