|
From: <sub...@co...> - 2005-12-30 20:36:31
|
Author: phd
Date: 2005-12-30 20:36:19 +0000 (Fri, 30 Dec 2005)
New Revision: 1445
Modified:
SQLObject/docs/FAQ.txt
Log:
Documented using applyConstraints for mutually referencing tables.
Modified: SQLObject/docs/FAQ.txt
===================================================================
--- SQLObject/docs/FAQ.txt 2005-12-30 20:18:32 UTC (rev 1444)
+++ SQLObject/docs/FAQ.txt 2005-12-30 20:36:19 UTC (rev 1445)
@@ -391,3 +391,35 @@
The reason for this limit is that each object needs a database ID, and
in many databases you cannot attain an ID until you create a row.
+Mutually referencing tables
+---------------------------
+
+How can I create mutually referencing tables? For the code::
+
+ class Person(SQLObject):
+ role = ForeignKey("Role")
+
+ class Role(SQLObject):
+ person = ForeignKey("Person")
+
+ Person.createTable()
+ Role.createTable()
+
+Postgres raises ProgrammingError: ERROR: relation "role" does not exist.
+
+The correct way is to delay constraints creation until all tables are
+created::
+
+ class Person(SQLObject):
+ role = ForeignKey("Role")
+
+ class Role(SQLObject):
+ person = ForeignKey("Person")
+
+ constraints = Person.createTable(applyConstraints=False)
+ constraints += Role.createTable(applyConstraints=False)
+
+ for constraint in constraints:
+ connection.query(constraint)
+
+Please be warned the delay can cause a race condition.
|