]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add doc example for column_property() on an association table per [ticket:1481]
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Jun 2011 21:18:41 +0000 (17:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Jun 2011 21:18:41 +0000 (17:18 -0400)
doc/build/orm/mapper_config.rst

index 259a6ecbab900384956c78d9fe5b46306cf55792..d69cff6426ba0070ffc52e32d2f8638efddbd7f5 100644 (file)
@@ -296,7 +296,22 @@ Correlated subqueries may be used as well::
             )
     })
 
-The declarative form of the above is described in :ref:`declarative_sql_expressions`.
+For many-to-many relationships, use :func:`.and_` to join the fields of the
+association table to both tables in a relation::
+
+    from sqlalchemy import and_
+
+    mapper(Author, authors, properties={
+        'book_count': column_property(
+                            select([func.count(books.c.id)], 
+                                and_(
+                                    book_authors.c.author_id==authors.c.id,
+                                    book_authors.c.book_id==books.c.id
+                                )))
+        })
+
+For examples of :func:`.column_property` using Declarative, see 
+:ref:`declarative_sql_expressions`.
 
 Note that :func:`.column_property` is used to provide the effect of a SQL
 expression that is actively rendered into the SELECT generated for a