question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Client: Fluent API chaining not working for PascalCase columns in 3.9.1

See original GitHub issue

Bug description

Prisma appears to have an issue resolving table names in sub selects. Prisma is essentially telling me that I’m attempting to query for a table using the camelCase version of the name, when I should be using the PascalCase version, but I’m already using PascalCase .

Error Message

Invalid `prisma.user.findUnique()` invocation:

{
  where: {
    UserID: 8667
  },
  select: {
    userRole: {
    ~~~~~~~~
      select: {
        Role: {
          select: {
            Id: true,
            Name: true
          }
        }
      }
    },
?   UserID?: true,
?   UserName?: true,
?   FirstName?: true,
?   MiddleName?: true,
?   LastName?: true,
?   UserRole?: true,
  }
}

Unknown field `userRole` for select statement on model User. Available options are listed in green. Did you mean `UserRole`?

How to reproduce

Run this query against the provided schema

const userRoles = await prisma.user.findUnique({
    where: { UserID: user.id }
  })
  .UserRole({
      select: {
          Role: { <shortened for brevity> }
      }
   }
});    

Expected behavior

This query should return the requested data

Prisma information

model User {
  UserID                                                                      Int                             @id(map: "PK_tblUser") @default(autoincrement())
  UserName                                                                    String?                         @unique(map: "IX_tblUser_1") @db.NVarChar(256)
  FirstName                                                                   String?                         @db.NVarChar(25)
  MiddleName                                                                  String?                         @db.NVarChar(25)
  LastName                                                                    String?                         @db.NVarChar(25)
  UserRole                                                                    UserRole[]                      @relation("UserRoleTotblUser")

  @@index([UserID, FirstName], map: "IX_tblUser_ByFirstName")
  @@index([UserID, LastName], map: "IX_tblUser_ByLastName")
  @@map("tblUser")
}

model UserRole {
  UserId         Int
  RoleId         Int
  Role           Role      @relation(fields: [RoleId], references: [Id], onUpdate: NoAction, map: "FK_UserRole_RoleId_To_Role_Id")
  tblUser        User      @relation("UserRoleTotblUser", fields: [UserId], references: [UserID], onUpdate: NoAction, map: "FK_UserRole_UserId_To_User_Id")

  @@id([UserId, RoleId], map: "PK_UserRole_UserId_RoleId")
}

model Role {
  Id              Int               @id(map: "PK_Role_Id") @default(autoincrement())
  Name            String            @unique(map: "UQ_Role_Name") @db.NVarChar(255)
  RoleEntitlement RoleEntitlement[]
  UserRole        UserRole[]
}

Environment & setup

  • OS: Windows, Alpine
  • Database: MS Sql Server
  • Node.js version: 16.X

Prisma Version

prisma                  : 3.9.1
@prisma/client          : 3.9.1
Current platform        : windows
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio                  : 0.457.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
millspcommented, Feb 10, 2022

Hey, the fix for this issue has been released via 3.9.2. Thank you for reporting this issue!

2reactions
pantharshit00commented, Feb 7, 2022

Hello,

I can reproduce this. Looks like a regression to me. I have updated the title to reflect the issue.

Reproduction: https://github.com/harshit-test-org/prisma-issue-11641

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma 3.10.0 Release - GitClear
We are working towards a stable release of MongoDB and are shipping lots of improvements. All the new features and changes in this...
Read more >
Using custom model and field names (Concepts) - Prisma
The Prisma Client API is generated based on the models in your Prisma schema. ... tables and columns from the names that are...
Read more >
@prisma/client 3.10.0 on Node.js Yarn - NewReleases.io
New release @prisma/client version 3.10.0 on Node.js Yarn. ... ObjectId · Prisma Client: Fluent API chaining not working for PascalCase columns in 3.9.1...
Read more >
Collibra Platform OSS Attribution File.txt
This Collibra product does not necessarily use all the open source ... 2.0 - Client (1.0.1) [Apache-2.0, MIT, JSON] - Apache Parquet Column...
Read more >
Codes not uploading on GitHub - QasimWani/LeetHub - IssueHint
did you pass all the test cases on the problem you submitted? ... Prisma Client: Fluent API chaining not working for PascalCase columns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found