diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-21 02:57:38 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-21 02:57:38 +0000 |
commit | a2ff73200cd6bfa465d13b8531c2745007ebf8c9 (patch) | |
tree | 123a5291900bbb8656fbcb17c44678740523d28d /lib/sqlalchemy/mapping/properties.py | |
parent | bec1b4f92ea23e41eebe90d184acff9c2918b175 (diff) | |
download | sqlalchemy-a2ff73200cd6bfa465d13b8531c2745007ebf8c9.tar.gz |
working on postupdate idea, refactoring to dependency processing
Diffstat (limited to 'lib/sqlalchemy/mapping/properties.py')
-rw-r--r-- | lib/sqlalchemy/mapping/properties.py | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index 571bfc0b5..036dfe440 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -358,14 +358,20 @@ class PropertyLoader(MapperProperty): uowcommit.register_processor(stub, self, self.parent, True) elif self.direction == PropertyLoader.ONETOMANY: if self.post_update: - raise InvalidRequestError("post_update not yet supported with one-to-many relation") - uowcommit.register_dependency(self.parent, self.mapper) - uowcommit.register_processor(self.parent, self, self.parent, False) - uowcommit.register_processor(self.parent, self, self.parent, True) + stub = PropertyLoader.MapperStub(self.mapper) + uowcommit.register_dependency(self.mapper, stub) + uowcommit.register_dependency(self.parent, stub) + uowcommit.register_processor(stub, self, self.parent, False) + uowcommit.register_processor(stub, self, self.parent, True) + else: + uowcommit.register_dependency(self.parent, self.mapper) + uowcommit.register_processor(self.parent, self, self.parent, False) + uowcommit.register_processor(self.parent, self, self.parent, True) elif self.direction == PropertyLoader.MANYTOONE: if self.post_update: stub = PropertyLoader.MapperStub(self.mapper) uowcommit.register_dependency(self.mapper, stub) + uowcommit.register_dependency(self.parent, stub) uowcommit.register_processor(stub, self, self.parent, False) uowcommit.register_processor(stub, self, self.parent, True) else: @@ -433,12 +439,12 @@ class PropertyLoader(MapperProperty): statement = self.secondary.insert() statement.execute(*secondary_insert) elif self.direction == PropertyLoader.MANYTOONE and delete: - # head object is being deleted, and we manage a foreign key object. - # dont have to do anything to it. if 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: self._synchronize(obj, None, None, True) - task.mapper.save_obj([obj], uowcommit, postupdate=True) + uowcommit.register_object(obj, postupdate=True) elif self.direction == PropertyLoader.ONETOMANY and 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 @@ -450,7 +456,7 @@ class PropertyLoader(MapperProperty): childlist = getlist(obj, False) for child in childlist.deleted_items() + childlist.unchanged_items(): self._synchronize(obj, child, None, True) - uowcommit.register_object(child) + uowcommit.register_object(child, postupdate=self.post_update) elif self.association is not None: # manage association objects. for obj in deplist: @@ -488,21 +494,16 @@ class PropertyLoader(MapperProperty): #print "DELETE ASSOC OBJ", repr(child) uowcommit.register_object(child, isdelete=True) else: - for obj in deplist: - if self.direction == PropertyLoader.MANYTOONE: - uowcommit.register_object(obj) + for obj in deplist: childlist = getlist(obj, passive=True) - if childlist is None: continue - for child in childlist.added_items(): - self._synchronize(obj, child, None, False) - if self.direction == PropertyLoader.ONETOMANY and child is not None: - if self.post_update: - task.mapper.save_obj([child],uowcommit, postupdate=True) - else: - uowcommit.register_object(child) - if self.post_update: - task.mapper.save_obj([obj], uowcommit, postupdate=True) - if self.direction != PropertyLoader.MANYTOONE or len(childlist.added_items()) == 0: + if childlist is not None: + for child in childlist.added_items(): + self._synchronize(obj, child, None, False) + if self.direction == PropertyLoader.ONETOMANY and child is not None: + uowcommit.register_object(child, postupdate=self.post_update) + if self.direction == PropertyLoader.MANYTOONE: + uowcommit.register_object(obj, postupdate=self.post_update) + if self.direction != PropertyLoader.MANYTOONE: for child in childlist.deleted_items(): if not self.private: self._synchronize(obj, child, None, True) |