blazingbowser
blazingbowser
TTCTheo's Typesafe Cult
Created by blazingbowser on 6/30/2023 in #questions
Why I am not able to use camelCase to use prisma models in trpc if I am using PascalCase name them
6 replies
TTCTheo's Typesafe Cult
Created by blazingbowser on 6/29/2023 in #questions
How to add Many to Many relation fields in `z.object` and how to write procedure for it ?
I have created these two models
model Category {
id String @id @default(cuid())
name String
created_at DateTime @default(now())
updated_at DateTime @updatedAt
products Product[]
}

model Product {
id String @id @default(cuid())
name String
description String?
selling_price Float
discount_price Float?
tags String[]
created_at DateTime @default(now())
updated_at DateTime @updatedAt
images Image[]
skus Sku[]
categories Category[]
}
model Category {
id String @id @default(cuid())
name String
created_at DateTime @default(now())
updated_at DateTime @updatedAt
products Product[]
}

model Product {
id String @id @default(cuid())
name String
description String?
selling_price Float
discount_price Float?
tags String[]
created_at DateTime @default(now())
updated_at DateTime @updatedAt
images Image[]
skus Sku[]
categories Category[]
}
I have already created categories. I want to write a procedure to create a product but I don't know how to add categories. How to define categories in z.object
create: adminProcedure
.input(
z.object({
name: z.string().min(1),
description: z.string().min(1),
selling_price: z.number().min(1),
discount_price: z.number().min(1),
categories : ???
}),
)
.mutation(({ ctx, input }) => {
return ctx.prisma.product.create({ data: input });
})
create: adminProcedure
.input(
z.object({
name: z.string().min(1),
description: z.string().min(1),
selling_price: z.number().min(1),
discount_price: z.number().min(1),
categories : ???
}),
)
.mutation(({ ctx, input }) => {
return ctx.prisma.product.create({ data: input });
})
do I have to add array of category_id or something else? Will the product will be automatically added to the category table? having same question for other fields too i.e. skus, images...
20 replies