Paulo Castellano
09/28/2022, 9:22 PMconst website = await prisma.website.create({
data: {
name: name,
domain: domain,
users: {
connect: {
userId: userId,
role: 'owner'
}
},
},
})
Austin
09/28/2022, 9:33 PMschema.prisma
and any errors you are seeing.Paulo Castellano
09/28/2022, 9:37 PMPaulo Castellano
09/28/2022, 9:39 PMconst website = await Kernel.prisma.website.create({
data: {
name: 'Google',
domain: '<http://google.com|google.com>',
users: {
connect: {
userId: '7b766d35-7cd9-4c39-860e-b71b4ceb680e',
~~~~~~
role: 'owner'
~~~~
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
}
})
Argument data.users.connect of type WebsiteUserWhereUniqueInput needs exactly one argument, but you provided userId and role. Please choose one. Available args:
type WebsiteUserWhereUniqueInput {
userId_websiteId?: WebsiteUserUserIdWebsiteIdCompoundUniqueInput
}
Paulo Castellano
09/28/2022, 9:39 PMAustin
09/28/2022, 9:55 PMWebsiteUser
model has a composite ID of userId
and websiteId
, so that’s what you have to pass in order to connect
the record. If you want to update the role
, that would happen in a subsequent update
call, possible in a transaction.Paulo Castellano
09/28/2022, 9:58 PMPaulo Castellano
09/28/2022, 10:01 PMawait prisma.website.update({
where: {
id: website.id
},
data: {
users: {
connect: {
id: request.user.id,
role: 'owner'
},
},
}
})
Paulo Castellano
09/28/2022, 10:19 PM// get user
const user = await prisma.user.findUnique({
where: {
id: request.user.id,
},
})
// create website
const website = await prisma.website.create({
data: {
name: name,
domain: domain
},
})
await prisma.WebsiteUser.create({
data: {
websiteId: website.id,
userId: request.user.id,
role: 'owner'
},
});
Austin
09/29/2022, 10:00 PMPaulo Castellano
09/30/2022, 2:04 AMPaulo Castellano
09/30/2022, 2:04 AMPaulo Castellano
09/30/2022, 2:04 AMAustin
10/04/2022, 6:31 PM