It is sometimes useful to map a class to joininstead of a single table when using the SQLAlchemy declarative extension. When column names collide, usually one-to-many, because by default all primary keys have a name id, you can use .alias()to prefix each column with its table name. This is inconvenient if you have already written code assuming that your mapped class has non-prefix names.
For example:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, ForeignKeyConstraint
Base = declarative_base()
t1 = Table('t1',
Base.metadata,
Column('id', Integer, primary_key=True))
t2 = Table('t2',
Base.metadata,
Column('id', Integer, primary_key=True),
Column('fkey', Integer),
ForeignKeyConstraint(['fkey'], [t1.c.id]))
class ST(Base):
__table__ = t1.join(t2)
class ST2(Base):
__table__ = t1.join(t2).alias()
ST id, fkey , , t2. ST2 t1_id, t2_id t2_fkey.
join, ?