Exercise 3: Choosing the Right Method — Possible Solution =========================================================== (a) Show one post from its URL slug findUnique({ where: { slug } }) — slug is @unique, so this is the most direct lookup and returns null if there's no such post, which the page can turn into a "not found" message. (findUniqueOrThrow also works if you'd rather catch a P2025 error.) (b) Find the most recent unpublished post findFirst — several posts may be unpublished, and you want just one, so it needs sorting too: findFirst({ where: { published: false }, orderBy: { createdAt: "desc" } }) (orderBy is covered in Chapter 6.) (c) Make sure an "about" page exists, creating it only if missing upsert({ where: { slug: "about" }, update: {}, create: { title: "About", slug: "about" } }) One call handles both cases. An empty update means an existing page is left alone. (d) Clear all posts before a test run deleteMany({}) — the one time an empty where is exactly what you want. Only ever point this at a test database. WHY THIS WORKS AS AN ANSWER ------------------------------ Each choice follows from whether the lookup is by a unique field, whether one or many records are affected, and whether the record might not exist yet.