sean oreilly
09/26/2022, 8:48 PMuserId
)`
⢠the thing that is confusing to me is that I have other modals that are setup very similarly and this is just causing me a lot of confusion.
This is my code:
const fakers = await Promise.all(
new Array(10).fill(1).map(async () => {
return {
email: faker.internet.email(),
name: faker.name.fullName(),
id: faker.datatype.string(),
username: faker.internet.userName(),
image: faker.internet.avatar(),
}
})
)
const fakeUsers = await Promise.all(
fakers.map(async (user) => {
return prisma.user.upsert({
where: { email: user.email },
update: {},
create: {
email: user.email,
name: user.name,
image: user.image,
username: user.username,
},
})
})
)
const suggestions = await Promise.all(
fakeSuggestions.map(async (suggestion, i) => {
return prisma.suggestion.upsert({
where: { title: suggestion.title },
update: {},
create: {
title: suggestion.title,
description: suggestion.description,
user: {
connect: {
id: fakeUsers[Math.floor(Math.random() * fakeUsers.length)].id,
},
},
category: {
connect: {
id: cats[Math.floor(Math.random() * cats.length)].id,
},
},
status: {
connect: {
type: stats[Math.floor(Math.random() * stats.length)].type,
},
},
},
})
})
)
// Votes
await Promise.all(
new Array(100).fill(1).map(async (i) => {
return prisma.vote.upsert({
where: {
id: Math.floor(Math.random() * 1000),
},
update: {},
create: {
user: {
connect: {
id: fakeUsers[Math.floor(Math.random() * fakeUsers.length)].id,
},
},
suggestion: {
connect: {
id: suggestions[Math.floor(Math.random() * suggestions.length)]
.id,
},
},
},
})
})
)
sean oreilly
09/26/2022, 8:49 PMmodel Vote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
suggestionId Int
suggestion Suggestion @relation(fields: [suggestionId], references: [id])
user User @relation(fields: [userId], references: [id])
}
Nurul
09/27/2022, 6:58 AMVladi Stevanovic
sean oreilly
09/27/2022, 12:58 PMVladi Stevanovic