Skn0tt/prisma-erd

wrong result -> (zero or one) is shown as (one and only one)

Closed this issue · 2 comments

7ganam commented

I have the following schema where an Incedent should have zero to one department but it is shown as one and only one departement

datasource db {
  provider = "postgres"
  url      = env("DATABASE_URL")
}
model Incident {
  id          String   @id @default(uuid())

  assignedDepartment Department? @relation(fields: [assignedDepartmentId], references: [id])
  assignedDepartmentId String? 

// optional to allow for an incident to have no assigned department --- not unique to allow for multiple incidents to be assigned to the same department
}

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

  assignedIncidents Incident[]
}

image

Skn0tt commented

The bug probably lives somewhere around here:

let thisSideMultiplicity = "||";
if (field.isList) {
thisSideMultiplicity = "}o";
} else if (!field.isRequired) {
thisSideMultiplicity = "|o";
}
const otherModel = dml.models.find((model) => model.name == otherSide);

I'd be happy to review a PR, if you open one!

7ganam commented

The bug probably lives somewhere around here:

let thisSideMultiplicity = "||";
if (field.isList) {
thisSideMultiplicity = "}o";
} else if (!field.isRequired) {
thisSideMultiplicity = "|o";
}
const otherModel = dml.models.find((model) => model.name == otherSide);

I'd be happy to review a PR, if you open one!

sure, I will submit a PR today