If you create a class with related joins and add items to the join, the entries on the intermediate table won't be deleted along with the object itself. I have found this really annoying.

Attached patch deletes these related join rows from all objects referring to the object being destroyed and from the joins of the object itself.

The patch is against the svn head as of today and is attached and also in the patch tracker:

http://sourceforge.net/tracker/index.php?func=detail&aid=1593174&group_id=74338&atid=540674


Regards,
        Markus
Index: main.py
===================================================================
--- main.py	(revision 2064)
+++ main.py	(working copy)
@@ -132,6 +132,11 @@
     for klass in classregistry.registry(registry).allClasses():
         if findDependantColumns(name, klass):
             depends.append(klass)
+        else:
+            for join in klass.sqlmeta.joins:
+                if isinstance(join, joins.SORelatedJoin) and join.otherClassName == name:
+                    depends.append(klass)
+                    break
     return depends
 
 def findDependantColumns(name, klass):
@@ -1498,10 +1503,28 @@
     def destroySelf(self):
         self.sqlmeta.send(events.RowDestroySignal, self)
         # Kills this object.  Kills it dead!
+
+        klass = self.__class__
+
+        # Free related joins on the base class
+        for join in klass.sqlmeta.joins:
+            if isinstance(join, joins.SORelatedJoin):
+                q = "DELETE FROM %s WHERE %s=%d" % (join.intermediateTable, join.joinColumn, self.id)
+                self._connection.query(q)
+
         depends = []
-        klass = self.__class__
         depends = self._SO_depends()
         for k in depends:
+            # Free related joins
+            for join in k.sqlmeta.joins:
+                if isinstance(join, joins.SORelatedJoin) and join.otherClassName == klass.__name__:
+                     q = "DELETE FROM %s WHERE %s=%d" % (join.intermediateTable, join.otherColumn, self.id)
+                     self._connection.query(q)
+
+            # Don't confuse the rest of the process
+            if len(cols) == 0:
+                continue
+
             cols = findDependantColumns(klass.__name__, k)
             query = []
             delete = setnull = restrict = False
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to