Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
Sorting with Prisma in a complicated relationship

I'm using Prisma with a MySQL database for a project, an online shop, where the same product can be sold by multiple suppliers.

At a certain part of my database I have a table structure such as this one:

  • Product (id, name, ...)
  • Supply (productId, supplier, price, stock, ...)

The Supply table represents the fact that a supplier sells a certain product. Obviously, a Product can have multiple Supply entries, as many as the number of suppliers that sell said product.

I'm looking to use Prisma's findMany operation to sort products by the lowest price out of all Supplies a product has. I can easily calculate this value after obtaining all products, and sort in that way, but that wouldn't be scalable, and I'm also using pagination with take and skip for efficiency purposes, rendering that alternative pointless.

As an example, say two Product products have two Supplies each:

  • Product X, sold by supplier A at 63€ and by supplier B at 75€
  • Product Y, sold by supplier B at 54€ and by supplier A at 60€

The natural result I'm looking for (when sorting in ascending order) would be:

  1. Product Y
  2. Product X

As product X's minimum Supply price is lower than product Y's minimum Supply value.

I've thoroughly researched Prisma's documentation regarding this situation and cannot find a solution. I would very much like to implement this using the orderBy property for the findMany operation instead of using raw SQL queries, as I have implemented many other types of sorting the Prisma way.

Any help regarding this issue is appreciated, thanks in advance.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda