Issue creating a record in an edge table

The function createCompanyAdmin worked a month ago when I initially wrote it, but I haven't needed it until today when I finally got that far in my UI. I had to refactor the endpoint to take form-data instead of just a json body, but didn't have to change anything db wise. I'm confused as to why it seems to be trying to create a Company, and yes the Company is in the database.
model Company {
id String @id @unique @default(uuid())

CompanyAdmins CompanyAdmin[]
}
model Company {
id String @id @unique @default(uuid())

CompanyAdmins CompanyAdmin[]
}
model CompanyAdmin {
companyId String
Company Company @relation(fields: [companyId], references: [id])

adminId String
User User @relation(fields: [adminId], references: [id])

@@id([companyId, adminId])
}
model CompanyAdmin {
companyId String
Company Company @relation(fields: [companyId], references: [id])

adminId String
User User @relation(fields: [adminId], references: [id])

@@id([companyId, adminId])
}
model User {
id String @id @unique @default(uuid())

AdminsCompany CompanyAdmin[]
}
model User {
id String @id @unique @default(uuid())

AdminsCompany CompanyAdmin[]
}
function assignCompanyAdmin(companyId, adminId) {
return db.companyAdmin.create({
data: {
company: { connect: { id: companyId } },
user: { connect: { id: adminId } },
},
});
}
function assignCompanyAdmin(companyId, adminId) {
return db.companyAdmin.create({
data: {
company: { connect: { id: companyId } },
user: { connect: { id: adminId } },
},
});
}
Error output
Argument `Company` is missing.
PrismaClientValidationError:
Invalid `db.companyAdmin.create()` invocation in
/home/jared/Work/mvp-rest-api/src/api/companies/admins/admins.services.js:6:26

3 const { createUser } = require('../../users/users.services');
4
5 function assignCompanyAdmin(companyId, adminId) {
→ 6 return db.companyAdmin.create({
data: {
company: {
connect: {
id: "76e3861d-23b6-4ecb-9d04-e25812e61208"
}
},
user: {
connect: {
id: "e4c0eef2-8ef1-44f6-95d7-e334985688e3"
}
},
+ Company: {
+ create: CompanyCreateWithoutCompanyAdminsInput | CompanyUncheckedCreateWithoutCompanyAdminsInput,
+ connectOrCreate: CompanyCreateOrConnectWithoutCompanyAdminsInput,
+ connect: CompanyWhereUniqueInput
+ }
}
})
Argument `Company` is missing.
PrismaClientValidationError:
Invalid `db.companyAdmin.create()` invocation in
/home/jared/Work/mvp-rest-api/src/api/companies/admins/admins.services.js:6:26

3 const { createUser } = require('../../users/users.services');
4
5 function assignCompanyAdmin(companyId, adminId) {
→ 6 return db.companyAdmin.create({
data: {
company: {
connect: {
id: "76e3861d-23b6-4ecb-9d04-e25812e61208"
}
},
user: {
connect: {
id: "e4c0eef2-8ef1-44f6-95d7-e334985688e3"
}
},
+ Company: {
+ create: CompanyCreateWithoutCompanyAdminsInput | CompanyUncheckedCreateWithoutCompanyAdminsInput,
+ connectOrCreate: CompanyCreateOrConnectWithoutCompanyAdminsInput,
+ connect: CompanyWhereUniqueInput
+ }
}
})
No description
Solution:
Try this? ```ts db.companyAdmin.create({ data: { Company: {...
Jump to solution
2 Replies
Solution
Nurul
Nurul4mo ago
Try this?
db.companyAdmin.create({
data: {
Company: {
connect: {
id: "76e3861d-23b6-4ecb-9d04-e25812e61208"
}
},
User: {
connect: {
id: "e4c0eef2-8ef1-44f6-95d7-e334985688e3"
}
}
db.companyAdmin.create({
data: {
Company: {
connect: {
id: "76e3861d-23b6-4ecb-9d04-e25812e61208"
}
},
User: {
connect: {
id: "e4c0eef2-8ef1-44f6-95d7-e334985688e3"
}
}
Yetzederixx
YetzederixxOP4mo ago
I'll give it a try this morning. Thanks Update it worked. Note, it worked a month ago with lower case, so I'm not sure. Thanks again @Nurul (Prisma)
Want results from more Discord servers?
Add your server