]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
document that strings are accepted with declarative/secondary
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Dec 2011 16:27:50 +0000 (11:27 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Dec 2011 16:27:50 +0000 (11:27 -0500)
doc/build/orm/relationships.rst
lib/sqlalchemy/ext/declarative.py

index 6bfd01edd856f4ea10461af861725f7d11e2ccb6..c2ab62487f7fedb82d4ccc0cf083c3c4ce16e24a 100644 (file)
@@ -174,6 +174,16 @@ is complete::
                         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
index dc84c5dfb6356d9428880a8e37834517af976ab4..46d267faae12f3837364434ba3a014d1f319a233 100755 (executable)
@@ -185,6 +185,15 @@ the :class:`.MetaData` object used by the declarative base::
         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``.