From: Mike Bayer Date: Wed, 22 Jun 2011 21:18:41 +0000 (-0400) Subject: - add doc example for column_property() on an association table per [ticket:1481] X-Git-Tag: rel_0_7_2~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=670b640c88d0dab31a0f4c9a9096e69b371bdd62;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add doc example for column_property() on an association table per [ticket:1481] --- diff --git a/doc/build/orm/mapper_config.rst b/doc/build/orm/mapper_config.rst index 259a6ecbab..d69cff6426 100644 --- a/doc/build/orm/mapper_config.rst +++ b/doc/build/orm/mapper_config.rst @@ -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