I’m seeding a db and curious the best practice for...
# prisma-client
d
I’m seeding a db and curious the best practice for informing foreign keys.
Copy code
const projects = ["project 1", "project 2"]
projects.forEach(async (p) => await db.project.create({data: {name: p}})

const dbProjects = db.project.findMany()
db.task.create({
  data: {
    name: 'some task',
    project: {connect: {id: dbProject.find((p) => p.name.includes("project 1")).id},
I’m getting TS errors with
dbProject.find
because of course it could be undefined… Is there a better way to be thinking about this?
r
@Devin 👋 I would suggest using a combination of
map
and
Promise.all
so that the Project is always available when you perform a
dbProject.find
d
Thanks, I think I know what you mean and I’ll give it a try. For speed I ended up hard-coding pk ID
👍 1