diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-22 21:25:10 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-03-22 21:25:10 +0000 |
| commit | 0d47db421cf2230fb97a1665aca5309913385cdb (patch) | |
| tree | 1f363b359ace6761c188bad35a6d2e08111a9d48 /lib/sqlalchemy/mapping | |
| parent | 66e1a8be687efb960cc502105a07cf831167ac08 (diff) | |
| download | sqlalchemy-0d47db421cf2230fb97a1665aca5309913385cdb.tar.gz | |
added some extra traversal for one-to-many/many-to-one "private" relations to allow single-object commits to cascade into private child objects
Diffstat (limited to 'lib/sqlalchemy/mapping')
| -rw-r--r-- | lib/sqlalchemy/mapping/properties.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index beda26ad7..e5bcee78c 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: |
