Search code examples
postgresqlnestjsrelationshipone-to-oneprisma

Prisma 1-1 relationship can't access data from both sides


So I have the following prisma schema setup in my Nest Project:

model users {
    id                  Int                 @id @default(autoincrement())
    uuid                String              @default(uuid())
    createdAt           DateTime            @default(now())
    updatedAt           DateTime            @updatedAt
    firstName           String
    authentication      authentications    @relation("Authentication", fields: [authenticationId], references: [id], onDelete: Cascade)
    authenticationId    Int
}

model authentications {
    id                          Int         @id @default(autoincrement())
    uuid                        String      @default(uuid())
    createdAt                   DateTime    @default(now())
    updatedAt                   DateTime    @updatedAt
    role                        Role        @default(USER)
    emailAddress                String      @unique
    password                    String
    isEmailConfirmed            Boolean     @default(false)
    currentHashedRefreshToken   String?
    user                        users?      @relation("Authentication")
}

enum Role {
  SUSPENSION    @map("SUSPENSION_ROLE")
  USER          @map("USER_ROLE")
  ADMIN         @map("ADMIN_ROLE")
}

Now I want to fetch the users from the Database. Therefor I call

await this._prismaService.users.findMany({});

... it returns undefined.

But when I execute the same statement with authentications instead, it works. Like so:

await this._prismaService.authentications.findMany({});

Can someone explain to me why this is happening? I just want to check if the user exists with a given UUID. Thank you for your help!


Solution

  • I've solved the issue by double checking all my Prisma setup. After Danila's comment, I noticed that I did something wrong in my middleware that was causing the issue.