---
title: "SQLAlchemy 2 In Practice - Chapter 5 - Advanced Many-To-Many Relationships"
url: https://daily.dev/posts/sqlalchemy-2-in-practice---chapter-5---advanced-many-to-many-relationships-bnnrusazl
source_url: https://blog.miguelgrinberg.com/post/sqlalchemy-2-in-practice---chapter-5---advanced-many-to-many-relationships
type: article
source: "Miguel Grinberg"
published: 2026-05-03T09:32:32.484Z
updated: 2026-05-03T09:33:32.513Z
tags: ["python", "backend"]
reading_time: 34
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SQLAlchemy 2 In Practice - Chapter 5 - Advanced Many-To-Many Relationships

**[Miguel Grinberg](https://daily.dev/sources/miguelgrinberg)** · 34 min read · 0 upvotes · 0 comments

## Summary

Chapter 5 of the SQLAlchemy 2 in Practice book covers advanced many-to-many relationships using the Association Object Pattern. It explains how to handle join tables with extra columns (like unit price and quantity in an orders system), introduces UUID primary keys, write-only relationships, and database migrations with Alembic. The chapter also covers complex aggregation queries including grouping by time periods, calculating order totals, and product review statistics across PostgreSQL, MySQL, and SQLite.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.miguelgrinberg.com/post/sqlalchemy-2-in-practice---chapter-5---advanced-many-to-many-relationships>

---

Tags: [#python](https://daily.dev/tags/python), [#backend](https://daily.dev/tags/backend)

[View this post on daily.dev](https://daily.dev/posts/sqlalchemy-2-in-practice---chapter-5---advanced-many-to-many-relationships-bnnrusazl)
