Hello here. A quick one: Does this seem to be the...
# orm-help
b
Hello here. A quick one: Does this seem to be the correct way to implement this relationship? I am curious about that zero or more piece:
Copy code
model IndicatorUnit {
  id           String @id @default(uuid()) @db.Uuid
  unit         String @unique
  display_name String @unique
  
  indicators Indicator[]

  @@map("indicator_unit")
}

model Indicator {
  id           String @id @default(uuid()) @db.Uuid
  
  report_type_id String
  indicator_unit_id String
  indicator_unit IndicatorUnit @relation(fields: [indicator_unit_id], references: [id])

  @@map("indicator")
}
n
Is the relationship between Indicator and IndicatorUnit One to Many?
b
An IndicatorUnit can be assigned to zero or more Indicators but an Indicator must always have one IndicatorUnit. We want to be able to create IndicatorUnits even if there are no indicators associated with them but when an Indicator is created, it MUST be assigned an IndicatorUnit.
n
It looks good to me
b
But how do I enforce that zero or more cardinality because Prisma doesn't allow me to do something like indicators Indicator?[]. My brain is still spinning, I guess I do not fully understand how this works.😀
n
https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#-modifier A List could contain zero or more items which you are essentially doing
b
Aaaw, thank you. Well noted! Appreciated 🙂
🙌 1