Commits

Mike Bayer  committed 58937c3

document that strings are accepted with declarative/secondary

  • Participants
  • Parent commits 76d872d

Comments (0)

Files changed (2)

File doc/build/orm/relationships.rst

                         secondary=lambda: association_table, 
                         backref="parents")
 
+With the declarative extension in use, the traditional "string name of the table"
+is accepted as well, matching the name of the table as stored in ``Base.metadata.tables``::
+
+    class Parent(Base):
+        __tablename__ = 'left'
+        id = Column(Integer, primary_key=True)
+        children = relationship("Child", 
+                        secondary="association", 
+                        backref="parents")
+
 .. _association_pattern:
 
 Association Object

File lib/sqlalchemy/ext/declarative.py

         id = Column(Integer, primary_key=True)
         keywords = relationship("Keyword", secondary=keywords)
 
+Like other :func:`.relationship` arguments, a string is accepted as well, 
+passing the string name of the table as defined in the ``Base.metadata.tables``
+collection::
+
+    class Author(Base):
+        __tablename__ = 'authors'
+        id = Column(Integer, primary_key=True)
+        keywords = relationship("Keyword", secondary="keywords")
+
 As with traditional mapping, its generally not a good idea to use 
 a :class:`.Table` as the "secondary" argument which is also mapped to
 a class, unless the :class:`.relationship` is declared with ``viewonly=True``.