question — is there a way to do an equivalent of “...
# orm-help
d
question — is there a way to do an equivalent of “having”? as in - I have a class “task” with child “type” (single foreign key).
Copy code
model task_type {
  id          String  @id @default(uuid())
  name        String     @unique
  tasks       task[]
  notes       String?
  order       Int         @default(0)
  parent_id   String?
  parent      task_type?  @relation(name: "parent", fields: [parent_id], references: [id])
  child_tasks task_type[] @relation(name: "parent")
  deleted     Boolean     @default(false)
  interval    Int         @default(0)
}

model task {
  id           String       @id @default(uuid())
  type         task_type    @relation(fields: [task_type_id], references: [id])
  task_type_id String
  task_events  task_event[]
  notes        String?
  data         Json?
  createdAt    DateTime    @default(now())
  last_work_done  DateTime?
  completedAt  DateTime?
  status       String      @default("started")
  parent_task  task?       @relation(name: "parent", fields: [parent_task_id], references: [id])
  parent_task_id String?
  child_tasks  task[]      @relation(name: "parent")
}
Some of the types have “interval” (numeric) and I want to find all the tasks whose (task_)type.interval field is zero.
✅ 1
a
Hey Dave! Would something like this work?
Copy code
const results = await prisma.task.findMany({
  where: {
    type: { interval: 0 }
  }
})
d
yes, thanks, that makes sense