From: Mike Bayer Date: Sat, 15 Oct 2005 03:11:48 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~534 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e9789d0afde22be08657d25ccaf787ddfebd570;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index 04f73f85c3..d6c22e22d1 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -724,6 +724,7 @@ class PropertyLoader(MapperProperty): uowcommit.register_dependency(self.parent, self.mapper) uowcommit.register_processor(self.parent, False, self, self.parent, False) uowcommit.register_processor(self.parent, True, self, self.parent, True) + #uowcommit.register_processor(self.mapper, False, self, self.parent, True) elif self.direction == PropertyLoader.RIGHT: uowcommit.register_dependency(self.mapper, self.parent) uowcommit.register_processor(self.mapper, False, self, self.parent, False) @@ -802,32 +803,40 @@ class PropertyLoader(MapperProperty): if len(secondary_insert): statement = self.secondary.insert() statement.execute(*secondary_insert) - # TODO: shouldnt this be for all deletes? propertyloader.RIGHT + delete should - # be explicitly named + elif self.direction == PropertyLoader.RIGHT and delete: + # head object is being deleted, and we manage a foreign key object. + # dont have to do anything to it. + pass elif self.direction == PropertyLoader.LEFT and delete: - if not self.private: - updates = [] - clearkeys = True - for obj in deplist: + # 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.private: + # if we are privately managed, then all our objects should + # have been marked as "todelete" already and no attribute adjustment is needed + return + updates = [] + clearkeys = True + for obj in deplist: + if not self.private: params = {} for bind in self.lazybinds.values(): params[bind.key] = self.parent._getattrbycolumn(obj, self.parent.table.c[bind.shortname]) updates.append(params) - childlist = getlist(obj, False) - for child in childlist.deleted_items() + childlist.unchanged_items(): - # TODO: if self.private, mark child objects to be deleted ? - self.primaryjoin.accept_visitor(setter) - uowcommit.register_deleted_list(childlist) - if len(updates): - values = {} - for bind in self.lazybinds.values(): - values[bind.shortname] = None - statement = self.target.update(self.lazywhere, values = values) - statement.execute(*updates) + childlist = getlist(obj, False) + for child in childlist.deleted_items() + childlist.unchanged_items(): + self.primaryjoin.accept_visitor(setter) + uowcommit.register_object(child) + uowcommit.register_deleted_list(childlist) + if len(updates): + values = {} + for bind in self.lazybinds.values(): + values[bind.shortname] = None + statement = self.target.update(self.lazywhere, values = values) + statement.execute(*updates) else: for obj in deplist: if self.direction == PropertyLoader.RIGHT: - task.append(obj) + uowcommit.register_object(obj) childlist = getlist(obj) if childlist is None: return uowcommit.register_saved_list(childlist) @@ -835,13 +844,13 @@ class PropertyLoader(MapperProperty): for child in childlist.added_items(): self.primaryjoin.accept_visitor(setter) if self.direction == PropertyLoader.LEFT: - task.append(child) + uowcommit.register_object(child) if self.direction != PropertyLoader.RIGHT or len(childlist.added_items()) == 0: clearkeys = True for child in childlist.deleted_items(): self.primaryjoin.accept_visitor(setter) if self.direction == PropertyLoader.LEFT: - task.append(child) + uowcommit.register_object(child) def _sync_foreign_keys(self, binary, obj, child, associationrow, clearkeys): """given a binary clause with an = operator joining two table columns, synchronizes the values diff --git a/test/objectstore.py b/test/objectstore.py index 84dd30dc17..693105a33a 100644 --- a/test/objectstore.py +++ b/test/objectstore.py @@ -334,6 +334,8 @@ UPDATE email_addresses SET user_id=:user_id, email_address=:email_address WHERE u2.user_name = 'user2modified' u1.addresses.append(a3) del u1.addresses[0] + objectstore.commit() + return self.assert_enginesql(db, lambda: objectstore.commit(), """UPDATE users SET user_name=:user_name WHERE users.user_id = :users_user_id [{'users_user_id': %d, 'user_name': 'user2modified'}]