Author: phd
Date: 2006-10-30 12:39:22 -0700 (Mon, 30 Oct 2006)
New Revision: 2051
Modified:
SQLObject/branches/0.7-bugfix/docs/News.txt
SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inherited_foreignKey.py
Log:
A patch by Tormod Ravnanger Landet <to...@la...> to fix a problem with foreign keys in InheritableSQLObject.
Modified: SQLObject/branches/0.7-bugfix/docs/News.txt
===================================================================
--- SQLObject/branches/0.7-bugfix/docs/News.txt 2006-10-30 19:38:53 UTC (rev 2050)
+++ SQLObject/branches/0.7-bugfix/docs/News.txt 2006-10-30 19:39:22 UTC (rev 2051)
@@ -15,8 +15,7 @@
* Fixed a number of unicode-related problems with newer MySQLdb.
-* InheritableSQLObject.selectBy() now correctly handles foreign keys, even
- foreign keys from the parent classes.
+* Fixed a number of bugs in InheritableSQLObject related to foreign keys.
* If the DB API driver returns timedelta instead of time (MySQLdb sometimes
does this) it is converted to time; but if the timedelta has days an
Modified: SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py 2006-10-30 19:38:53 UTC (rev 2050)
+++ SQLObject/branches/0.7-bugfix/sqlobject/inheritance/__init__.py 2006-10-30 19:39:22 UTC (rev 2051)
@@ -225,7 +225,8 @@
# create the current subclass otherwise we will leave
# the database in an inconsistent state.
for col in self.sqlmeta.columnList:
- if col._default == sqlbuilder.NoDefault and col.name not in kw:
+ if (col._default == sqlbuilder.NoDefault) and \
+ (col.name not in kw) and (col.foreignName not in kw):
raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, col.name)
self._parent = parentClass(kw=parent_kw, connection=self._connection)
Modified: SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inherited_foreignKey.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inherited_foreignKey.py 2006-10-30 19:38:53 UTC (rev 2050)
+++ SQLObject/branches/0.7-bugfix/sqlobject/inheritance/tests/test_inherited_foreignKey.py 2006-10-30 19:39:22 UTC (rev 2051)
@@ -18,11 +18,8 @@
_inheritable = False
paper = ForeignKey("Paper", default=None)
-def setup():
- setupClass(Note)
- setupClass(PersonWithNotes)
- setupClass(Paper)
- setupClass(EmployeeWithNotes)
+def test_foreignKey():
+ setupClass([Note, PersonWithNotes, Paper, EmployeeWithNotes])
note = Note(text="person")
PersonWithNotes(firstName='Oneof', lastName='Authors', note=note)
@@ -33,8 +30,6 @@
EmployeeWithNotes(firstName='Senior', lastName='Clerk', paper=paper)
PersonWithNotes(firstName='Some', lastName='Person')
-def test_inheritance():
- setup()
person = PersonWithNotes.get(1)
assert isinstance(person, PersonWithNotes) and not isinstance(person, EmployeeWithNotes)
@@ -75,3 +70,16 @@
employee = EmployeeWithNotes.selectBy()
assert employee.count() == 2
+
+
+class TestInheritableBase(InheritableSQLObject):
+ pass
+
+class TestInheritableForeignKey(TestInheritableBase):
+ base = ForeignKey("TestInheritableBase")
+
+def test_foreignKey2():
+ setupClass([TestInheritableBase, TestInheritableForeignKey])
+
+ test = TestInheritableBase()
+ object = TestInheritableForeignKey(base=test)
|