From 5cd96623997691c59459058e2770908f1dbb9ddc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 28 Jun 2007 15:06:36 +0000 Subject: [PATCH] added extra session.clear() to enable example to work --- doc/build/content/datamapping.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/build/content/datamapping.txt b/doc/build/content/datamapping.txt index d91cc3cab0..b1fddfcd99 100644 --- a/doc/build/content/datamapping.txt +++ b/doc/build/content/datamapping.txt @@ -454,13 +454,18 @@ Note that when creating a relation with the `relation()` function, the target ca In the previous example, a single address was removed from the `addresses` attribute of a `User` object, resulting in the corresponding database row being updated to have a user_id of `None`. But now, theres a mailing address with no user_id floating around in the database of no use to anyone. How can we avoid this ? This is acheived by using the `cascade` parameter of `relation`: {python} + session.clear() # clear session clear_mappers() # clear mappers from the previous example + mapper(Address, addresses_table) mapper(User, users_table, properties = { 'addresses' : relation(Address, cascade="all, delete-orphan") } ) + # reload the user + u = session.query(User).get(u.user_id) + del u.addresses[1] u.addresses.append(Address('27 New Place', 'Houston', 'TX', '34839')) -- 2.47.2