0Pricing
Flask Academy · Lesson

Joins and Lazy vs Eager Loading

Avoid N+1 queries when traversing relations.

Querying Across Tables

Sometimes you filter parents by their children's data. A join lets one query span two related tables at once. 🔀

Write a join

Call join() on a query to pull a related model in, then filter on either side as one combined query.

q = User.query.join(Post).filter(Post.title == "Hi")

All lessons in this course

  1. Fetch Rows with query and get
  2. Filter, Order, and Limit Results
  3. Define Relationships and Foreign Keys
  4. Joins and Lazy vs Eager Loading
← Back to Flask Academy