Relations and joins
Load related records in the same query, filter by them, and write through them.
Include a relation
const authors = await db.user.include({ posts: true }).all();Filter by a relation
const prolific = await db.user.where({ posts: { some: { published: true } } }).all();Nested writes
await db.user.create({
data: { email: "sam@example.com", posts: { create: [{ title: "Hello" }] } },
});include runs one extra query per relation level. Three levels deep on a list of 500 is 1,501 rows fetched in four round trips — fine for an admin page, slow for a feed.
Updated
Was this page helpful?