add doc snip for column-based m2m
Issue #1481
resolved
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)
-
reporter -
reporter - removed milestone
Removing milestone: 0.7.2 (automated comment)
- Log in to comment
670b640c88d0dab31a0f4c9a9096e69b371bdd62