From ae53c42d3c6748a15cbd0b5b1b5d90d59bf9d3ca Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 29 Dec 2011 11:27:50 -0500 Subject: document that strings are accepted with declarative/secondary --- lib/sqlalchemy/ext/declarative.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index dc84c5dfb..46d267faa 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -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``. -- cgit v1.2.1