For this particular case, I don't think you need other joins.

A simple:

client = Client.get(1)
for x in client.projects: print x.projectDesc

should work.

However, if you have lots of rows in projects(for each client), beware
of the memory implication as everything will be retrieved once you
start to access it.

Basically, SQLObject can handle TWO table N to N situation pretty well.
It is when you need complex cross table retrieve/update then you need
to go back to raw SQL, as that kind of situation just cannot be
modeled.

Steve Bergman wrote:
> I am having trouble understanding how to use SQLObject in a relational
> way in TurboGears.
>
> I have classes in model.py that look something like the definitions below.
>
> I want to generate an html table that includes a line for each existing
> "Project" item and which includes the fields:
>
> clientName,  clientAddress, clientCity, clientState, ClientZip,
> projectDesc ProjectHours, billable
>
> What is the SQLObject way of getting a suitable result set for
> generating such a table? (I'm using PostgreSQL)
>
> I think I need to be using LEFTJOINOn or similar, but it seems to simply
> return the text of an SQL query and I have not been able to figure out
> how to use the result it returns.
>
>
> Thanks for any enlightenment.
>
> -Steve
>
> -----------------
>
> class Client(SQLObject):
>     _connection = hub
>
>     clientName   = StringCol(length=50)
>     clientAddress = StringCol(length=50)
>     clientCity=StringCol(length=25)
>     clientState=StringCol(length=2)
>     clientZip=StringCol(length=10)
>     projects     = MultipleJoin('Project')
>
>
> class Project(SQLObject):
>     _connection = hub
>
>     projectDesc   = StringCol(length=50)
>     projectHours  = DecimalCol(size=6, precision=2)
>     billable      = EnumCol(enumValues=['y','n','c'])
>     clientId        = ForeignKey('Client')
>     client        = SingleJoin('Client')

Reply via email to