From: Mike Bayer Date: Thu, 3 May 2007 23:32:11 +0000 (+0000) Subject: - "delete-orphan" no longer implies "delete". ongoing effort to X-Git-Tag: rel_0_3_8~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=591b1d975b4d9469b56a9621c0863b2edd2a5b32;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - "delete-orphan" no longer implies "delete". ongoing effort to separate the behavior of these two operations. --- diff --git a/CHANGES b/CHANGES index d1c0df4542..daa2e1e57e 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ - _Label class overrides compare_self to return its ultimate object. meaning, if you say someexpr.label('foo') == 5, it produces the correct "someexpr == 5". +- orm + - "delete-orphan" no longer implies "delete". ongoing effort to + separate the behavior of these two operations. - mysql - support for column-level CHARACTER SET and COLLATE declarations, as well as ASCII, UNICODE, NATIONAL and BINARY shorthand. diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index 86c0316f22..063d5aaa9d 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -180,6 +180,8 @@ 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: for obj in deplist: childlist = self.get_object_dependencies(obj, uowcommit, passive=self.passive_deletes) @@ -211,6 +213,8 @@ class OneToManyDP(DependencyProcessor): # 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) diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 6cb4fed6ed..923dd67977 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -15,7 +15,7 @@ class CascadeOptions(object): def __init__(self, arg=""): values = util.Set([c.strip() for c in arg.split(',')]) self.delete_orphan = "delete-orphan" in values - self.delete = "delete" in values or self.delete_orphan or "all" 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 diff --git a/test/orm/relationships.py b/test/orm/relationships.py index cc7eec9152..6fb666dab6 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -410,7 +410,7 @@ class RelationTest4(testbase.ORMTest): class B(object):pass for cascade in ( "save-update, delete", - "save-update, delete-orphan", + #"save-update, delete-orphan", "save-update, delete, delete-orphan"): mapper(B, tableB, properties={ @@ -437,7 +437,7 @@ class RelationTest4(testbase.ORMTest): class B(object):pass for cascade in ( "save-update, delete", - "save-update, delete-orphan", + #"save-update, delete-orphan", "save-update, delete, delete-orphan"): mapper(A, tableA, properties={ 'bs':relation(B, cascade=cascade)