Recursive delete in google app engine

前端 未结 4 1164
长发绾君心
长发绾君心 2021-02-09 17:37

I\'m using google app engine with django 1.0.2 (and the django-helper) and wonder how people go about doing recursive delete. Suppose you have a model that\'s something like thi

4条回答
  •  故里飘歌
    2021-02-09 18:22

    You need to implement this manually, by looking up affected records and deleting them at the same time as you delete the parent record. You can simplify this, if you wish, by overriding the .delete() method on your parent class to automatically delete all related records.

    For performance reasons, you almost certainly want to use key-only queries (allowing you to get the keys of entities to be deleted without having to fetch and decode the actual entities), and batch deletes. For example:

    db.delete(Bottom.all(keys_only=True).filter("daddy =", top).fetch(1000))
    

提交回复
热议问题