add doc snip for column-based m2m

Issue #1481 resolved
Mike Bayer repo owner created an issue
Thanks for the help. By the way, I suggest adding this example to the
documentation; I know it would have saved me a lot of head-banging. I
suggest the following text tacked at the end of "SQL Expressions as
Mapped Attributes" in "Mapper Configuration":

For many-to-many relationships, use and_() to join the fields of the
association table to both tables in a relation:

mapper(Author, authors, properties={
    'books': relation(Book, secondary=book_authors,
backref='authors'),
    'book_count': column_property(select([func.count(books.c.id)](func.count(books.c.id)), and_
(book_authors.c.author_id==authors.c.id,
book_authors.c.book_id==books.c.id)).label('books_count'))
    })

Comments (2)

  1. Log in to comment