Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv1697
Modified Files:
SQLObject.py
Log Message:
* Minor fixed to addNeedSet stuff
* foreignKey columns return None when the associated ID column is NULL
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** SQLObject.py 26 May 2003 21:48:54 -0000 1.40
--- SQLObject.py 30 May 2003 02:18:45 -0000 1.41
***************
*** 85,104 ****
cls = findClass(needClass, registry=registryName)
for obj, attr in q:
! setattr(obj, attr, cls)
except KeyError:
newNeedClassDict[needClass] = q
needSet[registryName] = newNeedClassDict
-
-
-
- def addNeedSet(needClass, setCls):
- needSet.setdefault(needClass.__name__, []).append(
- (needClass.__name__, setCls))
-
def addNeedSet(obj, setCls, registry, attr):
try:
cls = findClass(setCls, registry=registry)
! setattr(obj, attr, cls)
return
except KeyError:
--- 85,103 ----
cls = findClass(needClass, registry=registryName)
for obj, attr in q:
! if callable(getattr(obj, attr, None)):
! getattr(obj, attr)(cls)
! else:
! setattr(obj, attr, cls)
except KeyError:
newNeedClassDict[needClass] = q
needSet[registryName] = newNeedClassDict
def addNeedSet(obj, setCls, registry, attr):
try:
cls = findClass(setCls, registry=registry)
! if callable(getattr(obj, attr, None)):
! getattr(obj, attr)(cls)
! else:
! setattr(obj, attr, cls)
return
except KeyError:
***************
*** 470,474 ****
# self._SO_class_className is a reference
# to the class in question.
! getter = eval('lambda self: self._SO_class_%s(self.%s)' % (column.foreignKey, instanceName(name)))
else:
# Same non-caching version as above.
--- 469,473 ----
# self._SO_class_className is a reference
# to the class in question.
! getter = eval('lambda self: self._SO_foreignKey(self.%s and self._SO_class_%s)' % (column.foreignKey, instanceName(name)))
else:
# Same non-caching version as above.
***************
*** 724,727 ****
--- 723,732 ----
% (self.__class__.__name__, self.id)
return results[0]
+
+ def _SO_foreignKey(self, id, joinClass):
+ if id is None:
+ return None
+ else:
+ return joinClass(id)
def new(cls, **kw):
|