[SQLObject] Strange bug with SQLObject 0.6
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Carlos R. <car...@gm...> - 2004-10-15 21:10:32
|
Hello all. I'm writing a prototype using sqlobjects and sqlite, and
I've run into a strange problem. It may be a dumb mistake of mine (as
I often do :-), but I was not able to spot it. This is the test code:
-----
from sqlobject import connectionForURI, SQLObject, StringCol, IntCol, \
FloatCol, ForeignKey, MultipleJoin
db = connectionForURI('sqlite:/work/test.db')
class dbWorkItem(SQLObject):
_connection = db
wi_name = StringCol(length = 60, notNone = True)
wi_description = StringCol(length = 200, notNone = True, default = '')
wi_form_class = StringCol(length = 40, notNone = True)
wi_form_id = IntCol(default=0)
owner = ForeignKey('dbUser')
workflow = ForeignKey('dbWorkFlow')
class dbUser(SQLObject):
_connection = db
user_nickname = StringCol(length = 15, notNone = True, alternateID = True)
user_password = StringCol(length = 15, notNone = True, default = '')
user_name = StringCol(length = 40, notNone = True, default = '')
user_address1 = StringCol(length = 40, notNone = False, default = '')
user_address2 = StringCol(length = 40, notNone = False, default = '')
user_city = StringCol(length = 40, notNone = False, default = '')
user_comments = StringCol(length = 400, notNone = False, default = '')
workitems = MultipleJoin('dbWorkItem')
def new_db():
dbUser.createTable()
dbWorkItem.createTable()
dbUser(user_nickname="cribeiro", user_name="Carlos Ribeiro")
dbWorkItem(wi_name='task1', wi_description='Task 1',
wi_form_class='', workflow=None, owner=1)
dbWorkItem(wi_name='task2', wi_description='Task 2',
wi_form_class='', workflow=None, owner=1)
>>> new_db()
>>> u = dbUser.get(1)
>>> u
<dbUser 1 user_address1='' user_password='' user_address2=''
user_city='' user_name='Carlos Ribeiro' user_nickname='cribeiro'
user_comments=''>
>>> u.workitems
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'dbUser' object has no attribute 'workitems'
>>> u.user_name
'Carlos Ribeiro'
>>> wi = dbWorkItem.get(1)
>>> wi
<dbWorkItem 1 wi_form_class='' wi_form_id=0 wi_name='Entra nota
fiscal' workflowID=None ownerID=1 wi_description='Entra nota fiscal'>
>>> wi.owner
<dbUser 1 user_address1='' user_password='' user_address2=''
user_city='' user_name='Carlos Ribeiro' user_nickname='cribeiro'
user_comments=''>
>>> wi.owner is u
True
For some reason, I cant access the dbUser.workitems property. I tried
the example provided in the documentation (using Person and Address
entities), and it works. What am I missing here?
--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: car...@gm...
mail: car...@ya...
|