Chapter 11.1.1. One-to-Many Relationships (MultipleJoin)

One-to-many relationships means that object A has or contains multiple objects of type B. For example, a Python module may contain multiple functions, but a function belongs to a single module. Let’s represent this relationship with SQLObject classes:

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

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

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

The PythonFunction class has a module_id attribute, which is a foreign key [1] of the PythonModule it belongs to. The PythonModule class has ...

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.