Check out the FAQ on the SQLObject page:
http://sqlobject.org/FAQ.html#how-can-i-do-a-left-join
I haven't done it yet, but their docs are fabulous. Please let us know
how it goes!
SuperJared
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.
As for your error, you may need to use "personID" rather than person as
that seems to be a requirement for foreign key field.
persons = Person.select(some condition)
for x in persons:
for y in persons.addresses:
print x.name, y.address
Or turn it into a list of tuples
[(x.name, y.address) for x in persons for y in x.addresses]
A poor man's SELECT statement.
Of course it is not as clean as SQL(especially when you have complex
situation). OODB may be a fashionable thing but plain old SQL beats it
for real applications. In fact, even in my good old ISAM days(on IBM
systems), I used multiple pass programs to flatten trees like the above
for reporting.
Use both in SQLObject, it is possible.
http://thraxil.org/users/anders/posts/2005/04/18/raw-queries-with-SQLObject/
Also, you can use database view to mimick that, that is not very
dynamic though.
>
> Generally speaking, when working with an OR mapper you *want* to work
> with your objects. You get all of the appropriate behavior, and you
> also get your objects cached. One should very infrequently be wanting
> to pull "raw" data from the database.
But that as Steve said, is too dBase/ISAM like which is going backward
for many situation. There is no need to pull raw data but a need to
turn a result set from a SQL query as an SQLObject and use the
excellent mapping of SQLObject that does all the internal data
conversion etc.