[SQL-CVS] r2104 - SQLObject/tags/0.7.2/docs
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2006-11-23 15:18:29
|
Author: phd
Date: 2006-11-23 08:18:24 -0700 (Thu, 23 Nov 2006)
New Revision: 2104
Modified:
SQLObject/tags/0.7.2/docs/FAQ.txt
SQLObject/tags/0.7.2/docs/News.txt
Log:
Merged the last doc update from the 0.7-bugfix branch.
Modified: SQLObject/tags/0.7.2/docs/FAQ.txt
===================================================================
--- SQLObject/tags/0.7.2/docs/FAQ.txt 2006-11-20 19:37:25 UTC (rev 2103)
+++ SQLObject/tags/0.7.2/docs/FAQ.txt 2006-11-23 15:18:24 UTC (rev 2104)
@@ -103,6 +103,51 @@
.. _SQLBuilder: SQLBuilder.html
.. _example: SQLObject.html#how-can-i-join-a-table-with-itself
+
+How can I define my own intermediate table in my Many-to-Many relationship?
+---------------------------------------------------------------------------
+
+.. note::
+ In User and Role, SQLRelatedJoin is used with createRelatedTable=False
+ so the intermediate table is not created automatically. We also set the
+ intermediate table name with intermediateTable='user_roles'.
+ UserRoles is the definition of our intermediate table.
+ UserRoles creates a unique index to make sure we don't have duplicate
+ data in the database.
+ We also added an extra field called active which has a boolean value.
+ The active column might be used to activate/deactivate a given role for
+ a user in this example.
+ Another common field to add in this an intermediate table might be a sort
+ field.
+
+We'll expand on the User and Role example and define our own UserRoles class which
+will be the intermediate table for the User and Role Many-to-Many relationship.
+
+Example::
+
+ >>> class User(SQLObject):
+ ... class sqlmeta:
+ ... table = "user_table"
+ ... username = StringCol(alternateID=True, length=20)
+ ... roles = SQLRelatedJoin('Role',
+ ... intermediateTable='user_roles',
+ ... createRelatedTable=False)
+
+ >>> class Role(SQLObject):
+ ... name = StringCol(alternateID=True, length=20)
+ ... users = SQLRelatedJoin('User',
+ ... intermediateTable='user_roles',
+ ... createRelatedTable=False)
+
+ >>> class UserRoles(SQLObject):
+ ... class sqlmeta:
+ ... table = "user_roles"
+ ... user = ForeignKey('User', notNull=True, cascade=True)
+ ... role = ForeignKey('Role', notNull=True, cascade=True)
+ ... active = BoolCol(notNull=True, default=False)
+ ... unique = index.DatabaseIndex(user, role, unique=True)
+
+
How Does Inheritance Work?
--------------------------
Modified: SQLObject/tags/0.7.2/docs/News.txt
===================================================================
--- SQLObject/tags/0.7.2/docs/News.txt 2006-11-20 19:37:25 UTC (rev 2103)
+++ SQLObject/tags/0.7.2/docs/News.txt 2006-11-23 15:18:24 UTC (rev 2104)
@@ -35,6 +35,12 @@
* A bug fix that allows to use SQLObject with DateTime from Zope.
+Documentation Added
+-------------------
+
+Added "How can I define my own intermediate table in my Many-to-Many relationship?" to FAQ.
+
+
SQLObject 0.7.1
===============
|