TRPC mutation example with relationships

Hey, I'm building an e-commerce site as a side project but I'm not sure how to make use of the mutation method with relationships. Have anyone seen an example that handles these cases? This would be step where the user has entered his details in a form and I already have the Product(s) in the cart global state. My prisma schema is something like this:
model OrderItem {
id String @id @default(cuid())
quantity Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
orderId String
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
productId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
}

model OrderDetail {
id String @id @default(cuid())
orderId String
address String
city String
country String
postalCode String
phone String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
}

model Order {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
orderItems OrderItem[]
orderDetails OrderDetail[] // can't get not to be an array??
}
model OrderItem {
id String @id @default(cuid())
quantity Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
orderId String
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
productId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
}

model OrderDetail {
id String @id @default(cuid())
orderId String
address String
city String
country String
postalCode String
phone String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
}

model Order {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
orderItems OrderItem[]
orderDetails OrderDetail[] // can't get not to be an array??
}
I don't have any type errors like this but I'm wondering if I'm in the right direction. The source is here in case if you want to see the rest of the code https://github.com/esponges/t3-ecommerce
GitHub
GitHub - esponges/t3-ecommerce: lets try to build an ecommerce site...
lets try to build an ecommerce site with t3. Contribute to esponges/t3-ecommerce development by creating an account on GitHub.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server