Hi,
I apologize in advance if I'm making some dumb mistake :-)
I am refactoring some code, and I decided to try the inheritance stuff
with it. I have a class User that holds the basic user information
(username, name and password), and a class Usuario() that inherits
from User and add some fields with administrative info. Default system
users are of the plain 'User' type, company employees are of the
'Usuario' type. (the split is part of a plan to release the basic
library as a independent product.)
When I try to find a 'Usuario' by username, I found that I can't use
the byUsername method. I've trimmed the traceback below for
readability, as the details don't matter very much for this particular
problem:
File "/home/cribeiro/work/sidercom/wflib/dbsidercom.py", line 322,
in teste_02_cria_grupos_usuario
user = self.dbUsuario.byUsername(username)
File "<string>", line 1, in <lambda>
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line
1155, in _SO_fetchAlternateID
value)
File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 422, in _SO_selectOneAlt
return self.queryOne("SELECT %s FROM %s WHERE %s = %s" %
<...snipped...>
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
33, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column 'username'
in 'where clause'")
In short,
[1] dbUser.byUsername(myname)
works, while:
[2] dbUsuario.byUsername(myname)
do not, because queryOne is not able to make an automatic join for
inherited tables.
I am not sure if this is a design feature, or if it's simply because
nobody has reported it before. The problem is that the form [1] wil
happily retrieve objects of any type. I need to retrieve objects of
the type [2] only.
I believe that a generic solution for this problem may well be out of
scope for SQLObject. However, in this particular case - alternate keys
- it should be possible to implement a simple & specific solution. The
question is, would it be welcome? and also, where am I supposed to
look at? Should I write a specific queryOne method for the
InheritableSQLObject class?
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro@...
mail: carribeiro@...
|