Rob
05/06/2022, 9:56 AMmodel Author {
id Int @id
name String
posts Post[]
}
model Post {
id Int @id
title String
author Author
}
prisma.post.findMany({
orderBy: [{
author: {
name: 'asc'
}
}]
})
So my problem (looking at the above example from the github issue) is that I actually DO want to order the authors on the post’s titles. And I was wondering in what ways I could achieve besides just using raw queries, which I obv. want to avoid..
Any help or advice is welcome! prisma green💌James L
05/06/2022, 10:09 AMorderBy
at both levels of the queryRob
05/06/2022, 10:11 AMorderBy
on-to-one relations. The one-to-many is limited on an aggregation ordering which only supports a count
Rob
05/06/2022, 10:11 AMprisma.author.findMany({
orderBy: [{
posts: {
title: 'asc'
}
}]
})
James L
05/06/2022, 10:13 AMRob
05/06/2022, 10:15 AMPostsOrderByRelationAggregateInput
Rob
05/06/2022, 10:15 AM{
_count?: SortOrder
}
Rob
05/06/2022, 10:16 AMRob
05/06/2022, 10:17 AMJames L
05/06/2022, 10:17 AMJames L
05/06/2022, 10:22 AMRob
05/06/2022, 10:26 AMJames L
05/06/2022, 10:27 AMJames L
05/06/2022, 10:27 AMChris Tsongas
05/06/2022, 5:09 PMinclude
i.e.
prisma.post.findMany({
include: {
author: true,
orderBy: {
name: 'asc'
}
},
orderBy: {
title: 'asc'
}
})
...or something like that, I just wrote it from memory but I'm sure you get the idea...let Prisma help you out by pressing control-spacebar in VS Code for hints.