#Ordering an isa relationship

1 messages · Page 1 of 1 (latest)

merry lark
#

for reference:

enum AddressType {
  PRIVATE
  COMPANY
}

model Address {
  id      Int        @id @default(autoincrement())
  type    PersonType
  Person  Person?
  Company Company?
}
 
model Private {
  id        Int        @id @default(autoincrement())
  firstname String
  lastname  String
  Address   Address   @relation(fields: [addressId], references: [id])
  addressId Int       @unique
}

model Company {
  id        Int        @id @default(autoincrement())
  name      String 
  Address   Address   @relation(fields: [addressId], references: [id])
  addressId Int       @unique
}

I'm trying to order my addresses by name but this doesn't work because they're optional.

const addresses = await prisma.address.findMany({
  orderBy: [
    { Person: { lastname: 'asc' } },
    { Company: { name: 'asc' } },
  ],
});
merry lark
#

Appearantly not available for relations.

#

Any suggestions how I can proceed without taking the raw query road?