Author: phd
Date: 2006-10-06 10:56:41 -0600 (Fri, 06 Oct 2006)
New Revision: 1987
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inheritance.py
Log:
Fixed a number of bugs in InheritableSQLMeta.{add,del}Column().
Modified: SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py 2006-10-05 18:02:20 UTC (rev 1986)
+++ SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py 2006-10-06 16:56:41 UTC (rev 1987)
@@ -91,8 +91,13 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic column as no child classes exists at object creation)
+ if columnDef and hasattr(soClass, "q"):
+ q = getattr(soClass.q, columnDef.name, None)
+ else:
+ q = None
for c in soClass._childClasses.values():
c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True)
+ if q: setattr(c.q, columnDef.name, q)
addColumn = classmethod(addColumn)
@@ -100,10 +105,15 @@
soClass = sqlmeta.soClass
super(InheritableSQLMeta, sqlmeta).delColumn(column, changeSchema, connection)
+ if isinstance(column, str):
+ name = column
+ else:
+ name = column.name
+
#DSM: Update each child class if needed
#DSM: and delete properties for this column
for c in soClass._childClasses.values():
- delattr(c, name)
+ delattr(c.q, name)
delColumn = classmethod(delColumn)
Modified: SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inheritance.py 2006-10-05 18:02:20 UTC (rev 1986)
+++ SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inheritance.py 2006-10-06 16:56:41 UTC (rev 1987)
@@ -78,3 +78,39 @@
person = Employee.byLastName("Leader")
assert person.firstName == "Project"
+
+def test_addDelColumn():
+ setup()
+
+ assert hasattr(InheritablePerson, "firstName")
+ assert hasattr(Employee, "firstName")
+ assert hasattr(InheritablePerson.q, "firstName")
+ assert hasattr(Employee.q, "firstName")
+
+ Employee.sqlmeta.addColumn(IntCol('runtime', default=None))
+
+ assert not hasattr(InheritablePerson, 'runtime')
+ assert hasattr(Employee, 'runtime')
+ assert not hasattr(InheritablePerson.q, 'runtime')
+ assert hasattr(Employee.q, 'runtime')
+
+ InheritablePerson.sqlmeta.addColumn(IntCol('runtime2', default=None))
+
+ assert hasattr(InheritablePerson, 'runtime2')
+ assert hasattr(Employee, 'runtime2')
+ assert hasattr(InheritablePerson.q, 'runtime2')
+ assert hasattr(Employee.q, 'runtime2')
+
+ Employee.sqlmeta.delColumn('runtime')
+
+ assert not hasattr(InheritablePerson, 'runtime')
+ assert not hasattr(Employee, 'runtime')
+ assert not hasattr(InheritablePerson.q, 'runtime')
+ assert not hasattr(Employee.q, 'runtime')
+
+ InheritablePerson.sqlmeta.delColumn('runtime2')
+
+ assert not hasattr(InheritablePerson, 'runtime2')
+ assert not hasattr(Employee, 'runtime2')
+ assert not hasattr(InheritablePerson.q, 'runtime2')
+ assert not hasattr(Employee.q, 'runtime2')
|