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

273
Views
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 answers
Answer question

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 Report
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!