Author: phd
Date: 2005-02-10 13:17:11 +0000 (Thu, 10 Feb 2005)
New Revision: 597
Modified:
home/phd/SQLObject/inheritance/sqlobject/inheritance/tests/test_inheritance.py
home/phd/SQLObject/inheritance/sqlobject/main.py
Log:
Fixed a bug with inhereted .q magic attribute.
Added more inheritance tests.
Modified: home/phd/SQLObject/inheritance/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- home/phd/SQLObject/inheritance/sqlobject/inheritance/tests/test_inheritance.py 2005-02-10 12:18:05 UTC (rev 596)
+++ home/phd/SQLObject/inheritance/sqlobject/inheritance/tests/test_inheritance.py 2005-02-10 13:17:11 UTC (rev 597)
@@ -16,14 +16,17 @@
_inheritable = 0 # If I don't want this class to be inherited
position = StringCol()
-
-def test_inheritance():
+def setup():
setupClass(Person)
setupClass(Employee)
Employee(firstName='Ian', lastName='Bicking', position='Project leader')
Person(firstName='Daniel', lastName='Savard')
+
+def test_inheritance():
+ setup()
+
persons = Person.select() # all
for person in persons:
assert isinstance(person, Person)
@@ -32,3 +35,16 @@
else:
assert hasattr(person, "childName")
assert not person.childName
+
+
+def test_inheritance_select():
+ setup()
+
+ persons = Person.select(Person.q.firstName <> None)
+ assert persons.count() == 2
+
+ employees = Employee.select(Employee.q.firstName <> None)
+ assert employees.count() == 1
+
+ employees = Employee.select(Employee.q.position <> None)
+ assert employees.count() == 1
Modified: home/phd/SQLObject/inheritance/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/inheritance/sqlobject/main.py 2005-02-10 12:18:05 UTC (rev 596)
+++ home/phd/SQLObject/inheritance/sqlobject/main.py 2005-02-10 13:17:11 UTC (rev 597)
@@ -577,15 +577,6 @@
cls.sqlmeta.idName = cls._idName
del cls._idName
- #DSM: If we are a child, get the q magic from the parent
- currentClass = cls
- while currentClass._parentClass:
- currentClass = currentClass._parentClass
- for column in currentClass._columns:
- if type(column) == col.ForeignKey: continue
- setattr(cls.q, column.name,
- getattr(currentClass.q, column.name))
-
# We have to check if there are columns in the inherited
# _columns where the attribute has been set to None in this
# class. If so, then we need to remove that column from
@@ -626,6 +617,15 @@
if not is_base:
cls.q = sqlbuilder.SQLObjectTable(cls)
+ #DSM: If we are a child, get the q magic from the parent
+ currentClass = cls
+ while currentClass._parentClass:
+ currentClass = currentClass._parentClass
+ for column in currentClass._columns:
+ if type(column) == col.ForeignKey: continue
+ setattr(cls.q, column.name,
+ getattr(currentClass.q, column.name))
+
classregistry.registry(cls._registry).addClass(cls)
_style = _sqlmeta_attr('style')
|