On Mon, 7 May 2007 at 14:00, Francis wrote:
> 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)
No, the naming transformations you describe have been around for a good
while.
> 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')
Why call this field module_id? It doesn't point to a module id, it
points to a module.
> 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)
You are jumping through hoops here that you don't need to jump through.
What you want to be doing is something like this (tested):
from sqlobject import *
connection = connectionForURI('sqlite:///:memory:')
sqlhub.processConnection = connection
class PythonFunction(SQLObject):
name = StringCol()
module = ForeignKey('PythonModule')
class PythonModule(SQLObject):
name = StringCol()
functions = MultipleJoin('PythonFunction', joinColumn='module_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=m)
f2 = PythonFunction(name='bar()', module=m)
f3 = PythonFunction(name='bar()', module=m)
assert len(m.functions) == 3
assert f1 in m.functions
assert f2 in m.functions
SQLObject handles the sql id logic in the background (the only exception
being the need to specify 'module_id' as the joinColumn, which is a bit
of a user interface bug).
--David
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---