Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kuaj opened this issue May 18, 2023 · 3 comments
Open

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

kuaj opened this issue May 18, 2023 · 3 comments

Comments

@kuaj
Copy link

kuaj commented May 18, 2023

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
Copy link

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

@rujorgensen
Copy link

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
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants