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

276
Visualizações
Update Field in Many to Many relation with Sequelize on NodeJs, with javascript

i have a relation Many to Many to do relation between Tournaments and Payers. So i have 3 models :

  • Player : with player_id
  • Tournament: with tournament_id
  • Participant (relation's table) witch join player_id, tournament_id, and contain un other field 'Status' to define if the player's participation to a tournament is 'accepted' or 'refused'.

My question is : how to do to update this field 'status' ?

I tried this, but is wrong !!!

const participation = await Participant.findAll({
        where: {
          user_id: userId,
          tournament_id: tournamentId,
        },
      });

await participation.update({ state: 'accepted' });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I am not sure this is the reason. But I assume that you shouldn't use the findAll method for your purpose.

findAll returns instance array, but update method belongs the model instance.

There are some possible solutions, I guess.

  1. Using Participant.findOne method and update it.

const participation = await Participant.findOne({ where: { user_id: userId, tournament_id: tournamentId });

  1. Using Participant.findAll method and loop the result array for update.

participation.map((p) => p.update({ state: 'accepted' });

  1. Using update method with where condition directly.

await Participant.update({ state: 'accepted' }, { where: { user_id: userId, tournament_id: tournamentId };

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