[SQL-CVS] r3961 - in SQLObject/trunk: docs sqlobject sqlobject/tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2009-08-18 16:41:56
|
Author: phd Date: 2009-08-18 10:41:42 -0600 (Tue, 18 Aug 2009) New Revision: 3961 Modified: SQLObject/trunk/docs/News.txt SQLObject/trunk/sqlobject/col.py SQLObject/trunk/sqlobject/tests/test_select.py Log: alternateMethodName for all unique fields, not only alternateID; this makes SQLObject create by*() methods for all unique fields. Modified: SQLObject/trunk/docs/News.txt =================================================================== --- SQLObject/trunk/docs/News.txt 2009-08-13 16:55:38 UTC (rev 3960) +++ SQLObject/trunk/docs/News.txt 2009-08-18 16:41:42 UTC (rev 3961) @@ -18,6 +18,9 @@ * Removed deprecated attribute and functions. +* alternateMethodName for all unique fields, not only alternateID; this + makes SQLObject create by*() methods for all unique fields. + SQLObject 0.11 ============== Modified: SQLObject/trunk/sqlobject/col.py =================================================================== --- SQLObject/trunk/sqlobject/col.py 2009-08-13 16:55:38 UTC (rev 3960) +++ SQLObject/trunk/sqlobject/col.py 2009-08-18 16:41:42 UTC (rev 3961) @@ -196,15 +196,15 @@ # alternateID means that this is a unique column that # can be used to identify rows self.alternateID = alternateID - if self.alternateID and alternateMethodName is None: - self.alternateMethodName = 'by' + self.name[0].capitalize() + self.name[1:] - else: - self.alternateMethodName = alternateMethodName if unique is NoDefault: self.unique = alternateID else: self.unique = unique + if self.unique and alternateMethodName is None: + self.alternateMethodName = 'by' + self.name[0].capitalize() + self.name[1:] + else: + self.alternateMethodName = alternateMethodName _validators = self.createValidators() if _validators: Modified: SQLObject/trunk/sqlobject/tests/test_select.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_select.py 2009-08-13 16:55:38 UTC (rev 3960) +++ SQLObject/trunk/sqlobject/tests/test_select.py 2009-08-18 16:41:42 UTC (rev 3961) @@ -103,6 +103,16 @@ return assert False, "IterTest(nonexistant='b') should raise TypeError" +class UniqTest(SQLObject): + name = StringCol(dbName='name_col', unique=True) + +def test_by_uniq(): + setupClass(UniqTest) + a = UniqTest(name='a') + b = UniqTest(name='b') + assert UniqTest.byName('a') is a + assert UniqTest.byName('b') is b + class Counter2(SQLObject): n1 = IntCol(notNull=True) |