From 6f1eb443a358f41f2dd38bac065b98fad54a67ce Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 3 Oct 2006 23:38:48 +0000 Subject: - "custom list classes" is now implemented via the "collection_class" keyword argument to relation(). the old way still works but is deprecated [ticket:212] --- examples/adjacencytree/byroot_tree.py | 9 ++++++--- examples/vertical/vertical.py | 5 +---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/adjacencytree/byroot_tree.py b/examples/adjacencytree/byroot_tree.py index 48793b936..6d86e587d 100644 --- a/examples/adjacencytree/byroot_tree.py +++ b/examples/adjacencytree/byroot_tree.py @@ -46,7 +46,6 @@ class TreeNode(object): identifiable root. Any node can return its root node and therefore the "tree" that it belongs to, and entire trees can be selected from the database in one query, by identifying their common root ID.""" - children = NodeList def __init__(self, name): """for data integrity, a TreeNode requires its name to be passed as a parameter @@ -118,6 +117,9 @@ print "\n\n\n----------------------------" print "Creating Tree Table:" print "----------------------------" +import logging +logging.getLogger('sqlalchemy.orm').setLevel(logging.DEBUG) + metadata.create_all() # the mapper is created with properties that specify "lazy=None" - this is because we are going @@ -128,10 +130,11 @@ mapper(TreeNode, trees, properties=dict( parent_id=trees.c.parent_node_id, root_id=trees.c.root_node_id, root=relation(TreeNode, primaryjoin=trees.c.root_node_id==trees.c.node_id, foreignkey=trees.c.node_id, lazy=None, uselist=False), - children=relation(TreeNode, primaryjoin=trees.c.parent_node_id==trees.c.node_id, lazy=None, uselist=True, cascade="delete,save-update"), + children=relation(TreeNode, primaryjoin=trees.c.parent_node_id==trees.c.node_id, lazy=None, uselist=True, cascade="delete,save-update", collection_class=NodeList), data=relation(mapper(TreeData, treedata, properties=dict(id=treedata.c.data_id)), cascade="delete,delete-orphan,save-update", lazy=False) -), extension = TreeLoader()) +), extension = TreeLoader()).compile() + session = create_session() diff --git a/examples/vertical/vertical.py b/examples/vertical/vertical.py index 66224fb5b..d4c8b9cae 100644 --- a/examples/vertical/vertical.py +++ b/examples/vertical/vertical.py @@ -50,9 +50,6 @@ class Entity(object): method is overridden to set all non "_" attributes as EntityValues within the _entities dictionary. """ - # establish the type of '_entities' - _entities = EntityDict - def __getattr__(self, key): """getattr proxies requests for attributes which dont 'exist' on the object to the underying _entities dictionary.""" @@ -125,7 +122,7 @@ mapper( ) mapper(Entity, entities, properties = { - '_entities' : relation(EntityValue, lazy=False, cascade='save-update') + '_entities' : relation(EntityValue, lazy=False, cascade='save-update', collection_class=EntityDict) }) # create two entities. the objects can be used about as regularly as -- cgit v1.2.1