Hello everybody! :wave: Maybe someone can help me ...
# prisma-whats-new
a
Hello everybody! 👋 Maybe someone can help me 🙏 I am looking for a way to orderBy a query based on the count of a node. However I did not find a way to do it. As the normal orderBy works only with fields and I am not sure how to do it. Example is pretty simple I have something like this:
Copy code
type Product @model {
  votes: [Vote!]! @relation(name: "VotesOnProduct")
}

type Vote @model {
  id: ID! @isUnique
  user: User! @relation(name: "UsersVotes")
  product: Product! @relation(name: "VotesOnProduct")
}
Now I want to orderBy my
allProducts
query based on the most votes.
b
I was wondering about what the best pattern for doing this was as well. If you had to have something like totalVotes, which kept track of the VoteConnection edge count, what would be the best way to keep it updated?
a
You can get the totalVotes over the _meta. However it is not possible to orderBy that meta value :c .
Copy code
query {
  allProducts (orderBy: createdAt_DESC) {
    title
    totalVotes: _votesMeta {
      count
    }
  }
}