Author: phd
Date: 2007-01-23 08:06:40 -0700 (Tue, 23 Jan 2007)
New Revision: 2230
Modified:
SQLObject/trunk/sqlobject/inheritance/__init__.py
SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py
Log:
Fixed bug 1640436: order by several columns and inheritance.
Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/__init__.py 2007-01-22 21:59:28 UTC (rev 2229)
+++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2007-01-23 15:06:40 UTC (rev 2230)
@@ -13,17 +13,30 @@
basestring = (types.StringType, types.UnicodeType)
+def tablesUsedDict(obj):
+ if hasattr(obj, "tablesUsedDict"):
+ return obj.tablesUsedDict()
+ elif isinstance(obj, (tuple, list)):
+ d = {}
+ for component in obj:
+ print component
+ d.update(tablesUsedDict(component))
+ return d
+ else:
+ return {}
+
+
class InheritableSelectResults(SelectResults):
IterationClass = iteration.InheritableIteration
def __init__(self, sourceClass, clause, clauseTables=None, **ops):
if clause is None or isinstance(clause, str) and clause == 'all':
clause = sqlbuilder.SQLTrueClause
- tablesDict = sqlbuilder.tablesUsedDict(clause)
+ tablesDict = tablesUsedDict(clause)
tablesDict[sourceClass.sqlmeta.table] = 1
orderBy = ops.get('orderBy')
if orderBy and not isinstance(orderBy, basestring):
- tablesDict.update(sqlbuilder.tablesUsedDict(orderBy))
+ tablesDict.update(tablesUsedDict(orderBy))
#DSM: if this class has a parent, we need to link it
#DSM: and be sure the parent is in the table list.
#DSM: The following code is before clauseTables
Modified: SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py 2007-01-22 21:59:28 UTC (rev 2229)
+++ SQLObject/trunk/sqlobject/inheritance/tests/test_inheritance.py 2007-01-23 15:06:40 UTC (rev 2230)
@@ -79,6 +79,24 @@
person = Employee.byLastName("Leader")
assert person.firstName == "Project"
+ persons = list(InheritablePerson.select(orderBy=InheritablePerson.q.lastName))
+ assert len(persons) == 2
+
+ persons = list(InheritablePerson.select(orderBy=(InheritablePerson.q.lastName, InheritablePerson.q.firstName)))
+ assert len(persons) == 2
+
+ persons = list(Employee.select(orderBy=Employee.q.lastName))
+ assert len(persons) == 1
+
+ persons = list(Employee.select(orderBy=(Employee.q.lastName, Employee.q.firstName)))
+ assert len(persons) == 1
+
+ persons = list(Employee.select(orderBy=Employee.q.position))
+ assert len(persons) == 1
+
+ persons = list(Employee.select(orderBy=(Employee.q.position, Employee.q.lastName)))
+ assert len(persons) == 1
+
def test_addDelColumn():
setup()
|