accesspatterns.dev

Modelling relationships · Lesson 12 of 20

Model a one-to-many with one partition

A parent and its children share a partition key, so one Query fetches them together.

Next · Modelling relationshipsOne key, every level

Why

A playlist has many tracks. Instead of a join, both live in one item collection: the playlist's META record and its TRACK items all share the partition key PLAYLIST#chill.

So 'the playlist and everything in it' is a single Query. The relationship was resolved at write time, by where you put the items, not at read time by joining them.

Co-locate a parent and its children under one partition key, and the join disappears into a single Query.

Playlists
Try an example

One Query on PLAYLIST#chill returns the playlist record and every track under it.

pk(pk)
sk(sk)
name
owner
title
seconds

Run an operation to see the raw engine response.

table Playlistskeys pk / skitems 26