SQLAlchemy joinedload vs. join()
· 7 min read
In SQLAlchemy, both the relationship loading option (.options(joinedload(...))) and the query builder method (.join(TableClass)) result in a SQL JOIN clause. However, they serve fundamentally different purposes and lead to distinct results in the ORM (Object Relational Mapper) layer.
Understanding this difference is crucial for avoiding the common "N+1 problem" and correctly shaping the data returned by your queries.
