Anton Tarasenko
Anton Tarasenko

Reputation: 8455

How to query an association table in SQLAlchemy?

I'd like to extract only pairs of keys stored in an association table in SQLAlchemy. One way is to create an association class and make something like session.query(Assoc).all().

Is it possible to query an association table in a similar fashion?

Upvotes: 3

Views: 1628

Answers (1)

davidism
davidism

Reputation: 127200

Tables can be queried just like declarative models. The query returns a list of keyed tuples rather than instances of a class.

session.query(my_table).all()

Upvotes: 3

Related Questions