PrismaP
Prisma12mo ago
3 replies
Uncle

Help with related filtering with some

With the following schema how do I search for all leases based on the size of a unit?
model Unit {
  num             String  @id @unique
  building        String
  size            String
  description     String
  leasedPrice     Int?
  advertisedPrice Int
  notes           String?
  unavailable     Boolean @default(false)
  lease           Lease[]

  @@index([num(sort: Desc)])
}
model Lease {
  leaseId              String        @id @unique @default(cuid(2))
  unitNum              String
  price                Int
  leaseCreatedAt       DateTime      @default(now())
  leaseEnded           DateTime?
  dropboxURL           String?
  anvilEID             String?       @unique
  stripeSubscriptionId String?
  invoices             Invoice[]
  unit                 Unit          @relation(fields: [unitNum], references: [num])


  @@unique([leaseId, unitNum, price])
  @@index([leaseId, leaseCreatedAt(sort: Desc)])
}

I get an error when I do
   const leases = await prisma.lease.findMany({
      where: {
         unit: {
            some: {
               size: '04x06'
            }
         }
      }
   })
Was this page helpful?