Hi everyone! I'm new to Prisma and generally is aw...
# orm-help
b
Hi everyone! I'm new to Prisma and generally is awesome, but im stuck on one thing... I'm using MySQL and got models like this:
Copy code
model User {
  id              String    @id @unique @default(cuid())
  user            String    @unique
  email           String    @unique
  first_name      String?
  last_name       String?
  skills          Skills[]
...
}

model Skills {
  id       String     @id @unique @default(cuid())
  can_play User[]
  type     SkillsList
}
When I try to "register user" i want to connect new user with Skills... Here is my code for create user right now:
Copy code
const result = await prisma.user.create({
    data: {
      user: user,
      email: email,
      password: password,
      first_name: first_name,
      last_name: last_name,
      skills: {
        connectOrCreate: skills.map((id: string) => ({
          where: { id: id },
        })),
      },
    },
  });
Skills is passing in string array with ID of skill, but I've got error:
Copy code
Unknown arg `where` in data.skills.connect.0.where for type SkillsWhereUniqueInput. Did you mean `id`? Available args:
type SkillsWhereUniqueInput {
  id?: String
}
Anyone can help me with this?
1
OK, brain recovery after sleep is awesome 🙂 i used :
Copy code
skills: {
        connect: skills.map((skill_id: string) => {
          return { id: skill_id };
        }),
      },
And it works perfectly 😄
🚀 1
n
In
connectOrCreate
you need to have
where
and
create
attributes both, it seems you just passed
where
which would have caused the issue.
connect
worked as you passed the unique field
id
through which records will be connected.