Hi Mike!
On 27.04.2013, at 05:56, Mike Orr <
slugg...@gmail.com> wrote:
> Are there any efficient techniques for selecting or deleting a tree of nodes? Or does it have to be one level's children at a time in a loop? I have two use cases:
>
> - Importing pages in bulk from an existing site. If it doesn't work right I want to be able to delete a subtree and try again.
If you delete the topmost node in the tree all children will also be
deleted. This should work OOTB, because the _children relation is
defined with cascade='all' (see
https://github.com/Kotti/Kotti/blob/master/kotti/resources.py#L221),
which implies 'delete'. This behavior is tested in
https://github.com/Kotti/Kotti/blob/master/kotti/tests/test_node.py#L117
and should thus work on all supported databases.
> - Comments. It seems like there should be a way to get a tree of comments related to a document in one query. But this doesn't seem to be possible if the comments are regular nodes. I'm wondering if it's worth making a separate comments table that's not a node, so that it can have a node_id field tying the tree of comments to the node. Is there a way to do this in the regular node/document tables?
DBSession().query(Comment).filter(Comment.parent_id ==
document_instance.id).delete()
HTH,
Andreas