notiz-dev / prisma-dbml-generator

Prisma DBML Generator
MIT License
684 stars 37 forks source link

TypeError: Cannot read properties of undefined (reading 'type') #51

Open kuaj opened 1 year ago

kuaj commented 1 year ago

Hey, there is some niche error for complex models (many to many)

TypeError: Cannot read properties of undefined (reading 'type')
    at getJoinIdType (/prisma-dbml-generator/dist/generator/many-to-many-tables.js:46:28)
    at joinField (/prisma-dbml-generator/dist/generator/many-to-many-tables.js:39:47)

I did hack around and that's because of multiple named relations that are completely valid within Prisma

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

generator dbml {
  provider      = "node ./dist/generator.js"
  mapToDbSchema = "false"
}

model Person {
  id String @id @default(uuid())

// this is the problematic definition
  SportClubMembers   SportClubMembers[]   @relation("member") 
  ScienceClubMembers ScienceClubMembers[] @relation("member")
}

model SportClub {
  id String @id @default(uuid())

  members SportClubMembers[]

  @@unique(id)
}

model ScienceClub {
  id String @id @default(uuid())

  members ScienceClubMembers[]

  @@unique(id)
}

//
// Relations
//

// Members on Somethings
model SportClubMembers {
  SportClub   SportClub @relation(fields: [sportClubId], references: id)
  sportClubId String
  Person      Person    @relation("member", fields: [personId], references: id)
  personId    String

  @@id([sportClubId, personId])
}

model ScienceClubMembers {
  ScienceClub   ScienceClub @relation(fields: [scienceClubId], references: id)
  scienceClubId String
  Person        Person      @relation("member", fields: [personId], references: id)
  personId      String

  @@id([scienceClubId, personId])
}
Tsimopak commented 6 months ago

@marcjulian Any update on this one? I experience this issue as well, I would really like to use this generator

rujorgensen commented 4 months ago

I've been experiencing this for the past few months as well. I regularly try to update, but keep having to downgrade to 0.10.0. So ... bump.

Let me know if there's anything I can do to help 🙂.

andreasciamanna commented 3 months ago

Two years on, the problem still occurs. Randomly, but it happens.

No much activity on this project either, which is a bit worrying but understandable.

> prisma generate --generator=dbml

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: 
Cannot read properties of undefined (reading 'type')

I'm commenting out this generator until this issue is resolved (if ever).