summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-06 13:29:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-06 13:29:13 -0500
commit8423dbcf62284e669c65afc258b0b993f8a66b6e (patch)
treeb714ab56a567e805803eff96707656654ae4e376 /lib/sqlalchemy/orm/util.py
parenta104f9d57d04864b139013632c7d3c7c98ab977c (diff)
downloadsqlalchemy-8423dbcf62284e669c65afc258b0b993f8a66b6e.tar.gz
- shave about a millisecond off of moderately complex save casades.
Diffstat (limited to 'lib/sqlalchemy/orm/util.py')
-rw-r--r--lib/sqlalchemy/orm/util.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index 23154bd4e..c59dbed69 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -21,7 +21,7 @@ all_cascades = frozenset(("delete", "delete-orphan", "all", "merge",
_INSTRUMENTOR = ('mapper', 'instrumentor')
-class CascadeOptions(object):
+class CascadeOptions(dict):
"""Keeps track of the options sent to relationship().cascade"""
def __init__(self, arg=""):
@@ -29,13 +29,17 @@ class CascadeOptions(object):
values = set()
else:
values = set(c.strip() for c in arg.split(','))
+
+ for name in ['save-update', 'delete', 'refresh-expire',
+ 'merge', 'expunge']:
+ boolean = name in values or 'all' in values
+ setattr(self, name.replace('-', '_'), boolean)
+ if boolean:
+ self[name] = True
self.delete_orphan = "delete-orphan" in values
- self.delete = "delete" in values or "all" in values
- self.save_update = "save-update" in values or "all" in values
- self.merge = "merge" in values or "all" in values
- self.expunge = "expunge" in values or "all" in values
- self.refresh_expire = "refresh-expire" in values or "all" in values
-
+ if self.delete_orphan:
+ self['delete-orphan'] = True
+
if self.delete_orphan and not self.delete:
util.warn("The 'delete-orphan' cascade option requires "
"'delete'. This will raise an error in 0.6.")
@@ -44,9 +48,6 @@ class CascadeOptions(object):
if x not in all_cascades:
raise sa_exc.ArgumentError("Invalid cascade option '%s'" % x)
- def __contains__(self, item):
- return getattr(self, item.replace("-", "_"), False)
-
def __repr__(self):
return "CascadeOptions(%s)" % repr(",".join(
[x for x in ['delete', 'save_update', 'merge', 'expunge',