Help with prisma nested create

I have this prisma model
model Membership {
userId String
groupId String
User User @relation(fields: [userId], references: [id])
Group Group @relation(fields: [groupId], references: [id])

@@id([userId, groupId])
}
model Membership {
userId String
groupId String
User User @relation(fields: [userId], references: [id])
Group Group @relation(fields: [groupId], references: [id])

@@id([userId, groupId])
}
, and I'm trying to create a Membership entry where the group is created nested. The reason for this is that, when I'm creating a new group, I need to also create a Membership entry. Instead of in one query creating the group, and in another creating the membership, I thought I would nest the group creation within the membership creation. I'm trying something along these lines
const groupResource = await ctx.prisma.membership.create({
data: {
userId: id,
Group: {
create: {
title: title,
slug: slugify(title),
ownerId: id,
}
}
},
});
const groupResource = await ctx.prisma.membership.create({
data: {
userId: id,
Group: {
create: {
title: title,
slug: slugify(title),
ownerId: id,
}
}
},
});
but am getting a long error, which I think roots from
Types of property 'userId' are incompatible.
Type 'string' is not assignable to type 'undefined'.ts(2322)
Types of property 'userId' are incompatible.
Type 'string' is not assignable to type 'undefined'.ts(2322)
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
jack
jackOP3y ago
just tried, still saying cant cast string to undefined; getting the impression that ownerId is undefined which doesn't make much sense to me, though prisma gets confusing quite quickly
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server