ok, I found the problem.

It seems that there's been a major change in naming variable since the
update to python 2.5 (probably not related to 2.5)

ForeignKey() add an extra 'ID' to the variable name, so 'module_id'
becomes 'modules_idID'.
But to call it with joinColumn, you have to use another convention
with an extra '_id'. So 'module_id' must be called with 'module_id_id'

So now we also have RORs magic...

here is the books corrected code:

class PythonFunction(SQLObject):
    name = StringCol()
    module_id = ForeignKey('PythonModule')

class PythonModule(SQLObject):
    name = StringCol()
    functions = MultipleJoin('PythonFunction',
joinColumn='module_id_id')

for table in [PythonFunction, PythonModule]:
    table.dropTable(ifExists=True)
    table.createTable()

m = PythonModule(name='xxx')
assert len( m.functions) == 0

f1 = PythonFunction(name='foo()', module_id=m.id)
f2 = PythonFunction(name='bar()', module_id=m.id)
f3 = PythonFunction(name='bar()', module_id=m)



On 4 mai, 14:08, Francis Lavoie <[EMAIL PROTECTED]> wrote:
> I have a contacts and phone number table class. The relationship is
> one-to-Many, as a contact can have multiple phone number, but a phone
> number can only be assigned to one contact.
>
> Here is my table base on the books example. (p167)
>
>         # Contacts
>         class Contacts(SQLObject):
>             name = UnicodeCol(alternateID=True, notNone=True, length=18)
>             contacts_type = EnumCol(enumValues=CATEGORY_LIST,
>         default=CATEGORY_LIST[1])
>             photo_logo = BLOBCol(default=DEFAULT_LOGO)
>             note = UnicodeCol()
>             hidden = BoolCol(default=False)
>             created_by  = UnicodeCol(notNone=True)
>             creation_date = DateTimeCol(notNone=True,
>         default=datetime.now)
>             group = ForeignKey('CGroups')
>             phones      = MultipleJoin('CPhoneBook',
>         joinColumn='contact_id')
>
>         # CPhoneBook
>         class CPhoneBook(SQLObject):
>             phone_number = IntCol(notNone=True)
>             category = EnumCol(enumValues=CATEGORY_LIST,
>         default=CATEGORY_LIST[1])
>             contact_id = ForeignKey('Contacts')
>
> Then I created a test account for it :
>
>         cg1 = CGroups(gname='testgroup')
>
>         # user1
>         c1 = Contacts(name=u'testcontact', note='', created_by=u'Admin',
>         group=cg1.id)
>         phone1 = CPhoneBook(phone_number=18887891234, contact_id=c1.id)
>
>         clientslist = Contacts.selectBy(hidden=False)
>         clients = clientslist[0]
>
> So now here's the problem. When I try to access the phone number I got
> this error:
>
>         clients.phones[0]
>         Traceback (most recent call last):
>           File "<console>", line 1, in <module>
>           File "<string>", line 1, in <lambda>
>           File
>         
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.0b2-py2.5.egg/sqlobject/joins.py",
>  line 144, in performJoin
>             inst.id)
>           File
>         
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.0b2-py2.5.egg/sqlobject/dbconnection.py",
>  line 691, in _SO_selectJoin
>             self.sqlrepr(value)))
>           File
>         
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.0b2-py2.5.egg/sqlobject/dbconnection.py",
>  line 840, in queryAll
>             return self._dbConnection._queryAll(self._connection, s)
>           File
>         
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.0b2-py2.5.egg/sqlobject/dbconnection.py",
>  line 348, in _queryAll
>             self._executeRetry(conn, c, s)
>           File
>         
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.0b2-py2.5.egg/sqlobject/sqlite/sqliteconnection.py",
>  line 183, in _executeRetry
>             raise OperationalError(ErrorMessage(e))
>         OperationalError: no such column: contact_idID
>
> I tried to replace the MultipleJoin('CPhoneBook',
> joinColumn='contact_id') to MultipleJoin('CPhoneBook',
> joinColumn='contact_idID'), but I still get the error.
>
> I have no idea where to look and it looks like exactly as in the book.
>
> Thank you
>
> Francis


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to