Howdy, I'm trying to get the TypeScript type for a...
# orm-help
a
Howdy, I'm trying to get the TypeScript type for a Model where I'm also selecting fields from a related model. If I use
import type { CartItem } from "@prisma/client";
, that type doesn't include the product fields. Here is my query:
Copy code
const items = await db.cartItem.findMany({
  select: { id: true, product: { select: { name: true, price: true } } },
  where: { userId }
});
Thanks
1
n
Hey Aydrian 👋 nice to see you here 😄 does this work for your scenario?
Copy code
import { Prisma } from '@prisma/client'

type CartItemWithProduct = Prisma.CartItemGetPayload<{
  select: {
    id: true,
    product: {
      select: {
        name: true,
        price: true
      }
    }
  } 
}>
a
Ah. That might work. I saw that in the docs but I'm a TypeScript newb. Let me give it a try.
a
Thank you. That worked.
💯 1