]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 15 Oct 2005 03:11:48 +0000 (03:11 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 15 Oct 2005 03:11:48 +0000 (03:11 +0000)
lib/sqlalchemy/mapper.py
test/objectstore.py

index 04f73f85c3304a0567bf4dfb3d24037719853990..d6c22e22d19c3d55c0a5175d7e72488c4d5c9ab3 100644 (file)
@@ -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 
index 84dd30dc17f55e2154509c1afeef8982fea7edfb..693105a33aaf1171d0544f2dc14978b0992b9cc5 100644 (file)
@@ -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'}]