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

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

问题描述

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



我的想法是这样的:

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

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



I还想在删除实体时删除BlobKeyProperties。为此,我想到

$ b $ pre code @classmethod
def _post_delete_hook(cls,key,future) :
#通知他们失去了一位朋友

我应该用它来级联删除对于无情的祖先查询,请从 com / appengine / docs / python / ndb / queryclass#构造函数rel =nofollow>查询类

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

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


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...

My thought was something like this:

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

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

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?

解决方案

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天全站免登陆