3

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

我的想法是这样的:

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

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

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

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

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

4

1 回答 1

6

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

于 2013-05-16T01:16:44.373 回答