PrismaP
Prisma2y ago
15 replies
battlesheep123

Relation not included in the generated types

Hello,

I have the following model, generated from a database-first approach.

model Entry {
  project       String    @db.Uuid
  description   String
  comment       String?
  status        String
  projects      Projects  @relation(fields: [project], references: [uuid], onDelete: NoAction, onUpdate: NoAction, map: "entry_projects_uuid_fk")

  @@map("entry")
}

model Projects {
  uuid         String      @id(map: "projects_pk") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  name         String
  entry        Entry[]

  @@map("projects")
}


The query:

const entries: Entry[] = await prisma.entry.findMany({
        include: {
            projects: true,
        },
    });

...returns the following data:

[
    {
        project: '5d117ed0-1391-4925-bde0-22412825cd54',
        description: 'xxxx',
        comment: 'xxx',
        status: 'xxx',
        projects: {
            uuid: '5d117ed0-1391-4925-bde0-22412825cd54',
            name: 'xxx'
        }
    }
]

Unfortunately, the generated Prisma type does not include the relation "projects". This means, the following typing does not include the relation.

const entries: Entry[] = await prisma.entry.findMany({ ... })

Any idea why that is?
Was this page helpful?