I'm currently struggeling with creating a new entr...
# orm-help
c
I'm currently struggeling with creating a new entry that is supposed to include a many to many relation. I can see that for input one of the following types is allowed: UserCreateInput or UserUncheckedCreateInput. However, if I run my query, it says "Unknown arg
groups
in create.groups for type UserUncheckedCreateInput." which is right, "groups" is not part of "UserUncheckedCreateInput" type, but it is of "UserCreateInput" type. I searched around on when prisma expects "Unchecked" Input type and when not, but couldn't find any. Who knows?
r
@Christian Goebel 👋 Could you share your schema and code for the new entry you’re creating? It could be that you’re missing a required field which is why the error pops up.
c
const admin = await prisma.user.upsert({
where: { email: "<mailto:admin@cgoebel.net|admin@cgoebel.net>" },
update: {},
create: {
email: "<mailto:admin@cgoebel.net|admin@cgoebel.net>",
firstName: "Christian",
lastName: "Goebel",
password: "password",
groups: {
connectOrCreate: {
where: { name: "SuperAdmin" },
create: {
name: "SuperAdmin",
roles: {
where: { name: "backendAdmin" },
create: { name: "backendAdmin" },
},
},
},
},
},
});
@Ryan and those are the involved tables:
model User {
id            String    @id @default(cuid())
name String?
firstName          String?
lastName          String?
email         String?   @unique
password String?
emailVerified DateTime?
image         String?
createdAt     DateTime  @default(now())
updatedAt     DateTime  @updatedAt
accounts      Account[]
sessions      Session[]
groups Group[]
roles Role[]
}
model Group {
id Int @id @default(autoincrement())
name String
users User[]
roles Role[]
}
model Role {
id Int @id @default(autoincrement())
name String
users User[]
groups Group[]
}
r
The User input looks fine. There’s an issue with your
connectOrCreate
for the
group
.
name
cannot be used in
where
as it’s not unique.
c
@Ryan thx! How could my query look then? I also tried „upsert“ but this resulted in the same error.
r
The above is fine, just replace
name
with
id
in the
where
argument of
connectOrCreate
.
c
Thanks! 🙏 If understand it write, the result of the where clause must by definition return just one entry, right?
r
Yeah