SQLAlchemy supports eager load for relationship, it is basically a JOIN
statement. However, if a model has two or more relationships, it could be a very huge join.
For a one-to-many or many-to-many relationship, it's (usually) better to use subqueryload instead, for performance reasons:
session.query(Product).join(User.addresses)\
.options(subqueryload(Product.orders),\
subqueryload(Product.tags)).all()
This issues separate SELECT
queries for each of orders
and tags
.