[SQL-CVS] r2074 - in SQLObject/branches/0.7-bugfix: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-11-10 15:34:58
|
Author: phd Date: 2006-11-10 08:34:47 -0700 (Fri, 10 Nov 2006) New Revision: 2074 Modified: SQLObject/branches/0.7-bugfix/docs/News.txt SQLObject/branches/0.7-bugfix/sqlobject/main.py SQLObject/branches/0.7-bugfix/sqlobject/tests/test_delete.py Log: The patch 1593174: Delete related join entries on destroySelf(). Modified: SQLObject/branches/0.7-bugfix/docs/News.txt =================================================================== --- SQLObject/branches/0.7-bugfix/docs/News.txt 2006-11-10 15:34:28 UTC (rev 2073) +++ SQLObject/branches/0.7-bugfix/docs/News.txt 2006-11-10 15:34:47 UTC (rev 2074) @@ -15,6 +15,8 @@ * sqlbuilder.Select now supports JOINs exactly like SQLObject.select. +* destroySelf() removes the object from related joins. + Bug Fixes --------- Modified: SQLObject/branches/0.7-bugfix/sqlobject/main.py =================================================================== --- SQLObject/branches/0.7-bugfix/sqlobject/main.py 2006-11-10 15:34:28 UTC (rev 2073) +++ SQLObject/branches/0.7-bugfix/sqlobject/main.py 2006-11-10 15:34:47 UTC (rev 2074) @@ -128,6 +128,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): @@ -1431,11 +1436,30 @@ def destroySelf(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) + cols = findDependantColumns(klass.__name__, k) + + # Don't confuse the rest of the process + if len(cols) == 0: + continue + query = [] delete = setnull = restrict = False for col in cols: Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_delete.py =================================================================== --- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_delete.py 2006-11-10 15:34:28 UTC (rev 2073) +++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_delete.py 2006-11-10 15:34:47 UTC (rev 2074) @@ -26,3 +26,22 @@ value = NoCache(name='test') value.destroySelf() NoCache._connection.cache = old + +######################################## +## Delete from related joins +######################################## + +class Service(SQLObject): + groups = RelatedJoin("ServiceGroup") + +class ServiceGroup(SQLObject): + services = RelatedJoin("Service") + +def testDeleteRelatedJoins(): + setupClass([Service, ServiceGroup]) + service = Service() + service_group = ServiceGroup() + service.addServiceGroup(service_group) + service.destroySelf() + service_group = ServiceGroup.get(1) + assert len(service_group.services) == 0 |