[SQL-CVS] r2689 - in SQLObject/branches/0.7: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2007-05-15 15:56:44
|
Author: phd Date: 2007-05-15 09:56:48 -0600 (Tue, 15 May 2007) New Revision: 2689 Modified: SQLObject/branches/0.7/docs/News.txt SQLObject/branches/0.7/sqlobject/joins.py SQLObject/branches/0.7/sqlobject/tests/test_SQLMultipleJoin.py SQLObject/branches/0.7/sqlobject/tests/test_SingleJoin.py Log: Replaced calls to style.dbColumnToPythonAttr() in joins.py by name/dbName lookup in case the user named columns differently using dbName. Modified: SQLObject/branches/0.7/docs/News.txt =================================================================== --- SQLObject/branches/0.7/docs/News.txt 2007-05-15 14:41:31 UTC (rev 2688) +++ SQLObject/branches/0.7/docs/News.txt 2007-05-15 15:56:48 UTC (rev 2689) @@ -10,6 +10,9 @@ SQLObject 0.7 ============= +* Replaced calls to style.dbColumnToPythonAttr() in joins.py by name/dbName + lookup in case the user named columns differently using dbName. + * Minor correction in the tests: we fully support EnumCol in Postgres. SQLObject 0.7.7 Modified: SQLObject/branches/0.7/sqlobject/joins.py =================================================================== --- SQLObject/branches/0.7/sqlobject/joins.py 2007-05-15 14:41:31 UTC (rev 2688) +++ SQLObject/branches/0.7/sqlobject/joins.py 2007-05-15 15:56:48 UTC (rev 2689) @@ -146,6 +146,12 @@ conn = None return self._applyOrderBy([self.otherClass.get(id, conn) for (id,) in ids if id is not None], self.otherClass) + def _dbNameToPythonName(self): + for column in self.otherClass.sqlmeta.columns.values(): + if column.dbName == self.joinColumn: + return column.name + return self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn) + class MultipleJoin(Join): baseClass = SOMultipleJoin @@ -156,7 +162,8 @@ conn = inst._connection else: conn = None - results = self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)) == inst.id, connection=conn) + pythonColumn = self._dbNameToPythonName() + results = self.otherClass.select(getattr(self.otherClass.q, pythonColumn) == inst.id, connection=conn) if self.orderBy is NoDefault: self.orderBy = self.otherClass.sqlmeta.defaultOrder return results.orderBy(self.orderBy) @@ -242,7 +249,7 @@ self.idName = idName self.interTable = interTable self.joinColumn = joinColumn - + def __sqlrepr__(self, db): return '%s.%s = %s.%s' % (self.interTable, self.joinColumn, self.table, self.idName) @@ -263,7 +270,7 @@ conn = None results = self.otherClass.select(sqlbuilder.AND( OtherTableToJoin( - self.otherClass.sqlmeta.table, self.otherClass.sqlmeta.idName, + self.otherClass.sqlmeta.table, self.otherClass.sqlmeta.idName, self.intermediateTable, self.otherColumn ), JoinToTable( @@ -294,7 +301,7 @@ conn = inst._connection else: conn = None - pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn) + pythonColumn = self._dbNameToPythonName() results = self.otherClass.select( getattr(self.otherClass.q, pythonColumn) == inst.id, connection=conn Modified: SQLObject/branches/0.7/sqlobject/tests/test_SQLMultipleJoin.py =================================================================== --- SQLObject/branches/0.7/sqlobject/tests/test_SQLMultipleJoin.py 2007-05-15 14:41:31 UTC (rev 2688) +++ SQLObject/branches/0.7/sqlobject/tests/test_SQLMultipleJoin.py 2007-05-15 15:56:48 UTC (rev 2689) @@ -3,12 +3,12 @@ class Race(SQLObject): name = StringCol() - fightersAsList = MultipleJoin('RFighter') - fightersAsSResult = SQLMultipleJoin('RFighter') + fightersAsList = MultipleJoin('RFighter', joinColumn="rf_id") + fightersAsSResult = SQLMultipleJoin('RFighter', joinColumn="rf_id") class RFighter(SQLObject): name = StringCol() - race = ForeignKey('Race') + race = ForeignKey('Race', dbName="rf_id") power = IntCol() def createAllTables(): Modified: SQLObject/branches/0.7/sqlobject/tests/test_SingleJoin.py =================================================================== --- SQLObject/branches/0.7/sqlobject/tests/test_SingleJoin.py 2007-05-15 14:41:31 UTC (rev 2688) +++ SQLObject/branches/0.7/sqlobject/tests/test_SingleJoin.py 2007-05-15 15:56:48 UTC (rev 2689) @@ -4,13 +4,13 @@ class PersonWithAlbum(SQLObject): name = StringCol() # albumNone returns the album or none - albumNone = SingleJoin('PhotoAlbum', joinColumn='person_id') + albumNone = SingleJoin('PhotoAlbum', joinColumn='test_person_id') # albumInstance returns the album or an default album instance - albumInstance = SingleJoin('PhotoAlbum', makeDefault=True, joinColumn='person_id') + albumInstance = SingleJoin('PhotoAlbum', makeDefault=True, joinColumn='test_person_id') class PhotoAlbum(SQLObject): color = StringCol(default='red') - person = ForeignKey('PersonWithAlbum') + person = ForeignKey('PersonWithAlbum', dbName='test_person_id') def test_1(): setupClass([PersonWithAlbum, PhotoAlbum]) |