From: Mike Bayer Date: Wed, 22 Mar 2006 21:25:10 +0000 (+0000) Subject: added some extra traversal for one-to-many/many-to-one "private" relations to allow... X-Git-Tag: rel_0_1_5~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d47db421cf2230fb97a1665aca5309913385cdb;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added some extra traversal for one-to-many/many-to-one "private" relations to allow single-object commits to cascade into private child objects --- diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index beda26ad74..e5bcee78cb 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -382,6 +382,7 @@ class PropertyLoader(MapperProperty): else: uowcommit.register_dependency(self.mapper, self.parent) uowcommit.register_processor(self.mapper, self, self.parent, False) + uowcommit.register_processor(self.mapper, self, self.parent, True) else: raise AssertionError(" no foreign key ?") @@ -444,7 +445,12 @@ class PropertyLoader(MapperProperty): statement = self.secondary.insert() statement.execute(*secondary_insert) elif self.direction == PropertyLoader.MANYTOONE and delete: - if self.post_update: + if self.private: + for obj in deplist: + childlist = getlist(obj, False) + for child in childlist.deleted_items() + childlist.unchanged_items(): + uowcommit.register_object(child, isdelete=True) + elif self.post_update: # post_update means we have to update our row to not reference the child object # before we can DELETE the row for obj in deplist: @@ -455,14 +461,20 @@ class PropertyLoader(MapperProperty): # the child objects have to have their foreign key to the parent set to NULL if self.private and not self.post_update: # if we are privately managed, then all our objects should - # have been marked as "todelete" already and no attribute adjustment is needed - return - for obj in deplist: - childlist = getlist(obj, False) - for child in childlist.deleted_items() + childlist.unchanged_items(): - if child is not None: - self._synchronize(obj, child, None, True) - uowcommit.register_object(child, postupdate=self.post_update) + # have been marked as "todelete" already and no attribute adjustment is needed. + # however, if they say objectstore.commit(x), i.e. on an individual object, + # then this extra step is more important. + for obj in deplist: + childlist = getlist(obj, False) + for child in childlist.deleted_items() + childlist.unchanged_items(): + uowcommit.register_object(child, isdelete=True) + else: + for obj in deplist: + childlist = getlist(obj, False) + for child in childlist.deleted_items() + childlist.unchanged_items(): + if child is not None: + self._synchronize(obj, child, None, True) + uowcommit.register_object(child, postupdate=self.post_update) elif self.association is not None: # manage association objects. for obj in deplist: