Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
Prisma - Cómo ordenar Usuarios por la cantidad de Publicaciones (orderBy y _count)

Encontré esta consulta en los documentos: dice "ordenar por el recuento de registros relacionados". que es exactamente lo que quiero.

 const getActiveUsers = await prisma.user.findMany({ take: 10, orderBy: { posts: { _count: 'desc', }, }, })

https://www.prisma.io/docs/concepts/components/prisma-client/filtering-and-sorting#sort-by-relation-aggregate-value

Aunque parece prometedor, no funciona y me da el siguiente error:

 { "errors": [ { "message": "\nInvalid `prisma.user.findMany()` invocation:\n\n{\n orderBy: {\n posts: {\n ~~~~~~~~~~~~~~\n _count: 'desc'\n }\n }\n}\n\nUnknown arg `posts` in orderBy.posts for type UserOrderByInput. Available args:\n\ntype UserOrderByInput {\n uid?: SortOrder\n username?: SortOrder\n pictureURL?: SortOrder\n}\n\n", "locations": [ { "line": 4, "column": 3 } ],

Aquí está mi esquema Prisma: es una relación simple de uno a muchos:

 model User { uid String @id @default(uuid()) username String? @db.VarChar(24) @unique pictureURL String? @db.VarChar(255) posts Posts[] @relation }

¿Qué me estoy perdiendo? ¿Tengo que usar palabras clave como "incluir" o "seleccionar" para que funcione?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!