Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 1 (modified by ajones1@…, 13 years ago) (diff)


Foreign Keys in SQLObject have a little bit of extra requirements due to the fact that they are mapping objects onto tables. For SQLObject to interact correctly with a foreign key relationship the object representing the table being referred to needs to know how the data is related. A code example will probably make this clearer.

class Person(SQLObject):
    firstName = StringCol()[[BR]]
    lastName = StringCol()[[BR]]
    address = MultipleJoin('Address')

class Address(SQLObject):
    street = StringCol()[[BR]]
    city = StringCol()[[BR]]
    state = StringCol(length=2)[[BR]]
    zip = StringCol(length=9)[[BR]]
    person = ForeignKey('Person')

The above pair of tables create a one to many relationship between the Person class (one) and the Address class (many). In addition to MultipleJoin there are methods for many-to-many relationships (RelatedJoin) and one-to-one relationships (SingleJoin). There are also additional keywords for these functions that add more features. See the  SQLObject Documentation for more details, but be aware that newer releases of SQLObject may change how these features are handled.