Neo Lambada
11/18/2021, 11:50 AMRyan
11/18/2021, 12:00 PMmodel User {
id Int @id @default(autoincrement())
name String
avatar String?
savedProducts Product[]
}
model Product {
id Int @id @default(autoincrement())
name String
price Int
users User[]
}
This would then take just a single Prisma call to fetch the users who have saved/bookmarked this product.Neo Lambada
11/18/2021, 12:28 PMNeo Lambada
11/18/2021, 12:29 PMNeo Lambada
11/18/2021, 12:30 PMRyan
11/18/2021, 12:35 PMlet userId = 1
let products = await prisma.product.findMany({
where: { stock: { gte: 1 } },
orderBy: { id: 'desc' },
include: { users: { where: { id: userId } } },
})
If the user exists in the product include
, it means that it is bookmarked and if the user doesnβt exist, it means that it is not bookmarkedRyan
11/18/2021, 12:36 PMexists
implemented, so it would be great if you could add a π to this request πNeo Lambada
11/18/2021, 12:38 PMNeo Lambada
12/24/2021, 4:00 PMmodel User {
id Int @id @default(autoincrement())
nidNumber Int?
name String @db.VarChar(255)
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @default(now()) @db.DateTime(0)
//relationships
savedProducts Product[]
}
model Product {
id Int @id @default(autoincrement())
code String @db.VarChar(255)
name String @db.VarChar(255)
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @default(now()) @db.DateTime(0)
//relations
users User[]
}
Neo Lambada
12/24/2021, 4:01 PMNeo Lambada
12/24/2021, 4:11 PM