Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prisma error: Cannot select both '$scalars: true' and a specific scalar field 'accountCompanies'

Tags:

node.js

prisma

I cannot solve this error. Any help?

Cannot select both '$scalars: true' and a specific scalar field 'accountCompanies'.


model Account {
  id String  @id @default(cuid())
  avatar String?
  lastName String
  firstName String

  accountCompanies AccountCompany[]
}

model Company {
  id String  @id @default(cuid())
  name String

  accountCompanies AccountCompany[]
}

model AccountCompany {
  account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
  accountId String
  company Company @relation(fields: [companyId], references: [id], onDelete: Cascade)
  companyId String
  role Role  @default(GENERAL)

  @@id(fields: [accountId, companyId])
}

The above error occurs in the code below.

  const account = await prisma.account.findUnique({
    where: { auth0UserId: auth0User.sub },
    include: { accountCompanies: true },
  });
like image 211
Yusuke Avatar asked Oct 26 '25 09:10

Yusuke


2 Answers

I had the same error, was able to clear it by restarting the TypeScript & Prism language servers in VSCode, and restarting the web server. That seems to be the recommended approach for resolving weird Prisma issues.

like image 177
Norman Elton Avatar answered Oct 28 '25 22:10

Norman Elton


For anyone else searching this same error message, as this was basically the only page I found for it.

I had this issue due to a capitalization bug. I meant to be referencing a relationship using 'Products' with a capital 'P', but I had accidentally written 'products' with a lower case 'p' in both the 'create' and 'include' section of the Prisma query.

like image 28
Levitybot Avatar answered Oct 28 '25 23:10

Levitybot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!