Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda