SQLAlchemy: get relationships from a db.Model
There is indeed - take a look at sqlalchemy.inspection.inspect
. Calling inspect
on a mapped class (for example, your Thing
class) will return a Mapper
, which has a relationships
attribute that is dict
like:
from sqlalchemy.inspection import inspect
thing_relations = inspect(Thing).relationships.items()
Instead of using inspect
you can also use
model.__mapper__.relationships