summaryrefslogtreecommitdiff
path: root/examples/adjacencytree/byroot_tree.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-10-23 03:46:20 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-10-23 03:46:20 +0000
commit722f97a826944073089998c42c48371a2514b9d6 (patch)
tree186a0811e53cd10ec87cdb9bb2d0bf18b65f4509 /examples/adjacencytree/byroot_tree.py
parent23b0eef7a13bb5c4cc9f30ac6a32502146723c14 (diff)
downloadsqlalchemy-722f97a826944073089998c42c48371a2514b9d6.tar.gz
Diffstat (limited to 'examples/adjacencytree/byroot_tree.py')
-rw-r--r--examples/adjacencytree/byroot_tree.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/adjacencytree/byroot_tree.py b/examples/adjacencytree/byroot_tree.py
index d352db4c7..ee1dd4a49 100644
--- a/examples/adjacencytree/byroot_tree.py
+++ b/examples/adjacencytree/byroot_tree.py
@@ -3,7 +3,7 @@ from sqlalchemy.schema import *
from sqlalchemy.sql import *
import sqlalchemy.util as util
import tables
-import string, sys
+import string, sys, time
"""a more advanced example of basic_tree.py. illustrates MapperExtension objects which
add application-specific functionality to a Mapper object."""
@@ -79,7 +79,7 @@ class TreeLoader(MapperExtension):
if instance.root is instance:
mapper.primarytable.update(TreeNode.c.id==instance.id, values=dict(root_node_id=instance.id)).execute()
instance.root_id = instance.id
- def append_result(self, mapper, row, imap, result, instance, populate_existing=False):
+ def append_result(self, mapper, row, imap, result, instance, isnew, populate_existing=False):
"""runs as results from a SELECT statement are processed, and newly created or already-existing
instances that correspond to each row are appended to result lists. This method will only
append root nodes to the result list, and will attach child nodes to their appropriate parent
@@ -88,8 +88,9 @@ class TreeLoader(MapperExtension):
if instance.parent_id is None:
result.append(instance)
else:
- parentnode = imap[mapper.identity_key(instance.parent_id)]
- parentnode.children.append(instance, _mapper_nohistory=True)
+ if isnew or populate_existing:
+ parentnode = imap[mapper.identity_key(instance.parent_id)]
+ parentnode.children.append(instance, _mapper_nohistory=True)
return False
class TreeData(object):