Hello, I think this might be a known thing but I s...
# orm-help
m
Hello, I think this might be a known thing but I struggle to find any solution. So I am using prisma and prisma client 3.14.0 as of now, and I wish to sort by relation like the following: const posts = await prisma.post.findMany({ orderBy: { author: { email: 'asc', }, }, }) Above is the documentation example, and I am struggling to implement this on my own schema. Where in the following query: let nodes = await prisma.node.findMany({ orderBy: { transactions: { time: 'desc', } }, }) prisma throws an error stating that `Unknown arg
time
in orderBy.transactions.time`
n
Hey Mark 👋 Could you share your node and transactions models?
m
Sure, here they are
model Node {
id              String          @id @default(cuid())
address         String          @unique
chains          Chain[]
public_key      String
jailed          Boolean
service_url     String
status          String
staked          Float
unstaking_time  String
balance         Float
sevenDayAverage Float           @default(0)
transactions    Transaction[]
users           NodeUser[]
node_daily_data NodeDailyData[]
}
model Transaction {
id           String   @id @default(cuid())
hash         String   @unique
height       Int
type         String?
from_address String?
total_pokt   Int?
in_out       String?
chain        String?
fee          String?
node         Node?    @relation(fields: [nodeId], references: [id])
nodeId       String?
testKey      String?
relays       Int?
time         DateTime
amount       Float?
app          String?
relayRate    Float?
confirmed    Boolean?
sessionKey   String?
}
@Nurul do you think you can help me?
👍 1
n
Hey Mark 👋 Could you try this?
Copy code
let nodes = await prisma.node.findMany({
    include: {
      transactions: {
        orderBy: {
          time: 'desc',
        },
      },
    },
  });
m
Hey @Nurul this approach sorts the transactions within the node entries, but doesn't sort the node entries themselves. Am I correct?