3

The sqlalchemy.sql module seems to assume that I've created Table instances, but I've specified my ORM using the Declarative style. Is there a way to extract the table instances from the Declarative classes? using session.query() seems to have worse syntax than the sqlalchemy.sql methods do.

1
  • could you provide some sample code? Commented Dec 21, 2009 at 9:45

1 Answer 1

3

You can get it from __table__ attribute of your model class:

# Some code is omitted

class Model(Base):
    __tablename__ = 'models'
    id = Column(Integer, primary_key=True)

print repr(Model.__table__)

Outputs:

Table('models', MetaData(None), Column('id', Integer(), table=<models>, 
primary_key=True, nullable=False), schema=None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.