Prisma 1 Forum

Populate relation on embedded document

My datamodel.prisma looks like this (i’ve left out the unimportant stuff):

type Order @db(name: "orders") {
  _id: ID! @id
  items: [OrderItem!]!
type OrderItem @embedded {
 product: Product! @relation(link: INLINE)
type Product @db(name: "products") {
  _id: ID! @id
 name: String!
 price: Int!

How can i populate the product field on the order.items?
I have the same schema on my backend (of course without the annotations), and i am not able to write a resolver to the product.
Also when i do

const orders = await prisma.orders()

in the items array there is no product.

Edit: i managed to get the products in items this way but its pretty ugly i think. Is there any other solution?

  const fragment = `
  fragment OrderWithProducts on Order {
    items {
      product {
  const orders = await prisma.orders().$fragment(fragment)

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.