summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-05-04 01:54:34 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-05-04 01:54:34 +0000
commitf8e8161cc97917b3d1f579943a860786ea4e151c (patch)
tree16acf3db21621afa5e498aa77cb741e5940d2dcc /lib/sqlalchemy
parent591b1d975b4d9469b56a9621c0863b2edd2a5b32 (diff)
downloadsqlalchemy-f8e8161cc97917b3d1f579943a860786ea4e151c.tar.gz
clarifying some cascade-based unit tests, adding a little more coverage,
and trying to remove unneeded parts of dependency.py cascades. also de-emphasizing the whole session.flush([oneobject]) thing since i dont really agree it should be supported
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/dependency.py26
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py19
2 files changed, 9 insertions, 36 deletions
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py
index 063d5aaa9..e623fd2a1 100644
--- a/lib/sqlalchemy/orm/dependency.py
+++ b/lib/sqlalchemy/orm/dependency.py
@@ -180,9 +180,9 @@ class OneToManyDP(DependencyProcessor):
if delete:
# head object is being deleted, and we manage its list of child objects
# the child objects have to have their foreign key to the parent set to NULL
-
- # TODO: this cascade should be "delete" cascade
- if not self.cascade.delete_orphan or self.post_update:
+ # this phase can be called safely for any cascade but is unnecessary if delete cascade
+ # is on.
+ if not self.cascade.delete or self.post_update:
for obj in deplist:
childlist = self.get_object_dependencies(obj, uowcommit, passive=self.passive_deletes)
if childlist is not None:
@@ -211,25 +211,7 @@ class OneToManyDP(DependencyProcessor):
if delete:
# head object is being deleted, and we manage its list of child objects
# the child objects have to have their foreign key to the parent set to NULL
- if self.post_update:
- pass
- # TODO: this block based on "delete_orphan" should technically be "delete", but also
- # is entirely not necessary
- elif self.cascade.delete_orphan:
- for obj in deplist:
- childlist = self.get_object_dependencies(obj, uowcommit, passive=self.passive_deletes)
- if childlist is not None:
- for child in childlist.deleted_items():
- if child is not None and childlist.hasparent(child) is False:
- uowcommit.register_object(child, isdelete=True)
- for c in self.mapper.cascade_iterator('delete', child):
- uowcommit.register_object(c, isdelete=True)
- for child in childlist.unchanged_items():
- if child is not None:
- uowcommit.register_object(child, isdelete=True)
- for c in self.mapper.cascade_iterator('delete', child):
- uowcommit.register_object(c, isdelete=True)
- else:
+ if not self.post_update and not self.cascade.delete:
for obj in deplist:
childlist = self.get_object_dependencies(obj, uowcommit, passive=self.passive_deletes)
if childlist is not None:
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 732970cad..c6b0b2689 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -192,25 +192,16 @@ class UnitOfWork(object):
# store objects whose fate has been decided
processed = util.Set()
-
- # put all saves/updates into the flush context. detect orphans and throw them into deleted.
+ # put all saves/updates into the flush context. detect top-level orphans and throw them into deleted.
for obj in self.new.union(dirty).intersection(objset).difference(self.deleted):
if obj in processed:
continue
- if object_mapper(obj)._is_orphan(obj):
- for c in [obj] + list(object_mapper(obj).cascade_iterator('delete', obj)):
- if c in processed:
- continue
- flush_context.register_object(c, isdelete=True)
- processed.add(c)
- else:
- flush_context.register_object(obj)
- processed.add(obj)
+
+ flush_context.register_object(obj, isdelete=object_mapper(obj)._is_orphan(obj))
+ processed.add(obj)
# put all remaining deletes into the flush context.
- for obj in self.deleted:
- if (objset is not None and not obj in objset) or obj in processed:
- continue
+ for obj in self.deleted.intersection(objset).difference(processed):
flush_context.register_object(obj, isdelete=True)
trans = session.create_transaction(autoflush=False)