From: Mike Bayer Date: Thu, 28 Jun 2007 15:06:36 +0000 (+0000) Subject: added extra session.clear() to enable example to work X-Git-Tag: rel_0_3_9~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cd96623997691c59459058e2770908f1dbb9ddc;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added extra session.clear() to enable example to work --- 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'))