per
10/29/2021, 1:48 PMconnect
to create a relation to the already existing player
in the database, which works perfectly.
I can’t seem to find how to make this connect
conditional though. The player 1 will always be there, but player 2 is not always provided (if the team only consists of only one player).
Prisma stops record creation that is sees that player 2 is not specified of course. How can I solve this issue?
Code below
export default async function createTeam(
req: NextApiRequest,
res: NextApiResponse
) {
const teamData = JSON.parse(req.body)
const team = await prisma.team.create({
data: {
player1: {
connect: {
id: teamData?.player1?.id,
},
},
player2: {
connect: {
id: teamData?.player2?.id,
},
},
groups: {
connect: {
id: 'group1-id-test',
},
},
},
})