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

254
Visualizações
How to get grouped results without Associations? (based on shared value)

When I have Associations relation I can do:

  const results = await categoryModel.findAll({
    include: [
      {
        model: moviesModel,
      },
    ]}

And I will get the results like:

{ category_id: 1, name: "action" movies: [list of movies in the category] }

Is there I can get the same type of result without the categoryModel to query on? To query directly the movies model and get the results like so? so they will be grouped based on the category ID that they have?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Sequelize is not about complex aggregation queries, it's just for CRUD with associations like any other ORM library.
You can only reduce attributes you want to get from the category model indicating the attributes option like this:

const results = await categoryModel.findAll({
    attributes: ['category_id'],
    include: [
      {
        model: moviesModel,
      },
    ]}
about 4 years ago · Juan Pablo Isaza Relatório
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