From 9047fab83bd1bd21bed2f1857cb35679c75712f3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 23 Sep 2006 16:37:43 +0000 Subject: [PATCH] remove delete-orphan cascade from self referential mappers --- doc/build/content/adv_datamapping.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/build/content/adv_datamapping.txt b/doc/build/content/adv_datamapping.txt index e2f5f8ffb4..6ce0dd6dd2 100644 --- a/doc/build/content/adv_datamapping.txt +++ b/doc/build/content/adv_datamapping.txt @@ -622,7 +622,7 @@ Note that with a circular relationship as above, you cannot declare both relatio ### Self Referential Mappers {@name=recursive} -A self-referential mapper is a mapper that is designed to operate with an adjacency list table. This is a table that contains one or more foreign keys back to itself, and is usually used to create hierarchical tree structures. SQLAlchemy's default model of saving items based on table dependencies is not sufficient in this case, as an adjacency list table introduces dependencies between individual rows. Fortunately, SQLAlchemy will automatically detect a self-referential mapper and do the extra lifting to make it work. +A self-referential mapper is a mapper that is designed to operate with an *adjacency list* table. This is a table that contains one or more foreign keys back to itself, and is usually used to create hierarchical tree structures. SQLAlchemy's default model of saving items based on table dependencies is not sufficient in this case, as an adjacency list table introduces dependencies between individual rows. Fortunately, SQLAlchemy will automatically detect a self-referential mapper and do the extra lifting to make it work. {python} # define a self-referential table @@ -642,7 +642,7 @@ A self-referential mapper is a mapper that is designed to operate with an adj TreeNode.mapper = mapper(TreeNode, trees, properties={ 'children' : relation( TreeNode, - cascade="all, delete-orphan" + cascade="all" ), } ) @@ -652,7 +652,7 @@ A self-referential mapper is a mapper that is designed to operate with an adj mymapper.add_property('children', relation( mymapper, - cascade="all, delete-orphan" + cascade="all" )) This kind of mapper goes through a lot of extra effort when saving and deleting items, to determine the correct dependency graph of nodes within the tree. @@ -677,7 +677,8 @@ A self-referential mapper where there is more than one relationship on the table 'children' : relation( TreeNode, primaryjoin=trees.c.parent_node_id==trees.c.node_id - cascade="all, delete-orphan" + cascade="all", + backref=backref("parent", foreignkey=trees.c.node_id) ), 'root' : relation( TreeNode, -- 2.47.2