summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/unitofwork.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-09-22 14:22:16 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-09-22 14:22:16 -0400
commiteae4de02a9b9bcf070a12607ada4098fb63e26f2 (patch)
treecbd9765b89832506b29d06454bcc4ce586d78f3e /lib/sqlalchemy/orm/unitofwork.py
parent7b8b23b42700598adf2ee79083aa13dbca5e75e7 (diff)
downloadsqlalchemy-eae4de02a9b9bcf070a12607ada4098fb63e26f2.tar.gz
- in depth docs about some merge() tips
- docs about backref cascade - Another new flag on relationship(), cascade_backrefs, disables the "save-update" cascade when the event was initiated on the "reverse" side of a bidirectional relationship. This is a cleaner behavior so that many-to-ones can be set on a transient object without it getting sucked into the child object's session, while still allowing the forward collection to cascade. We *might* default this to False in 0.7.
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 830ac3c0c..a9808e6ba 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -33,10 +33,13 @@ class UOWEventHandler(interfaces.AttributeExtension):
def append(self, state, item, initiator):
# process "save_update" cascade rules for when
# an instance is appended to the list of another instance
+
sess = _state_session(state)
if sess:
prop = _state_mapper(state).get_property(self.key)
- if prop.cascade.save_update and item not in sess:
+ if prop.cascade.save_update and \
+ (prop.cascade_backrefs or self.key == initiator.key) and \
+ item not in sess:
sess.add(item)
return item
@@ -55,11 +58,13 @@ class UOWEventHandler(interfaces.AttributeExtension):
# is attached to another instance
if oldvalue is newvalue:
return newvalue
+
sess = _state_session(state)
if sess:
prop = _state_mapper(state).get_property(self.key)
if newvalue is not None and \
prop.cascade.save_update and \
+ (prop.cascade_backrefs or self.key == initiator.key) and \
newvalue not in sess:
sess.add(newvalue)
if prop.cascade.delete_orphan and \