Chapter 11.3.2. Selecting from Multiple Tables

SQLBuilder is cool and everything, but sometimes you still need more. You need to get a result set that contains columns from multiple tables. Of course, you could just use MultipleJoin and RelatedJoin to express these relationships and always use them to retrieve the related items of a single object. This is useful but potentially inefficient (talks a lot to the DB), and you don’t always have control of the database to be able to add the relationships you want.

Once again, SQLObject has a solution. You can use SQLBuilder to create SQL join stantements for you. Let’s take a look at a Person class and a Book class, where each book has an author who is a person:

class Person(SQLObject): firstName ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.