From 4020f2f440b17b3637c19ac37a394646e0ddd21a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 16 Jul 2014 15:24:32 -0400 Subject: [PATCH] - also add the alternate approach, name column distinctly from attribute name, ref #3129 --- lib/sqlalchemy/ext/automap.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/sqlalchemy/ext/automap.py b/lib/sqlalchemy/ext/automap.py index a4f86c78a1..121285ab3a 100644 --- a/lib/sqlalchemy/ext/automap.py +++ b/lib/sqlalchemy/ext/automap.py @@ -432,6 +432,20 @@ We can resolve this conflict by using an underscore as follows:: Base.prepare(engine, reflect=True, name_for_scalar_relationship=name_for_scalar_relationship) +Alternatively, we can change the name on the column side. The columns +that are mapped can be modified using the technique described at +:ref:`mapper_column_distinct_names`, by assigning the column explicitly +to a new name:: + + Base = automap_base() + + class TableB(Base): + __tablename__ = 'table_b' + _table_a = Column('table_a', ForeignKey('table_a.id')) + + Base.prepare(engine, reflect=True) + + Using Automap with Explicit Declarations ======================================== -- 2.47.3