hello I am trying to sort by relation inside an `i...
# orm-help
d
hello I am trying to sort by relation inside an
include
but its not working. the relation sort does work at the
orderBy
Copy code
where,
include: {
	buyerGroupDescriptions: {
		where: {
			languageId
		},
		orderBy: {
			name: order // 'asc' or 'desc', not working
		}
	}
}
orderBy: {} // working
r
@Dev__ 👋 Could you share your schema so that I can check? Order by should work in the relation.
d
Copy code
model BuyerGroup {
    id        String   @id @db.VarChar(255)
    ...

    buyerGroupDescriptions BuyerGroupDescription[]
}

model BuyerGroupDescription {
    id           String   @id @db.VarChar(255)
    buyerGroupId String   @db.VarChar(255)
    languageId   String   @db.VarChar(255)
    name         String   @db.VarChar(255)
    ...

    buyerGroup BuyerGroup @relation(fields: [buyerGroupId], references: [id])
    language   Language   @relation(fields: [languageId], references: [id])

    @@unique([buyerGroupId, languageId])
}
I cant sort in the
orderBy
because then the relation
buyerGroupDescriptions
has a
_count
so I am forced to do it inside the
include
r
So it will then be ordered inside the
include
only.
The outer results will not be ordered.
d
ah I see, is there a way of doing it?
I need the outer results to be ordered
r
Not at the moment unfortunately: https://github.com/prisma/prisma/issues/5837
d
so it will take a while for it to be picked up?
dont wanna use raw query or js sort function...
r
Yeah it will take a while. I would suggest adding a 👍 and subscribing for more updates
👍 1