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

222
Views
Update a field of an associate table using the magic method of Sequelize/Node js

I have i table called Orders and another table called Cupons, this tables has a association many to one, Ordes has many cupons, and cupons belongs to order, i need to update the status of my cupom when i associate the cupons to a order, i tried this way but doesn't work

await item.addCupons(cupom.id, { // the item is the order created 
            through: {
                afiliado_id: afiliadoId, // and update the afiliado id 
                status: 'validado' // update de status of cupon to 'validado'
            }
        })
    ````
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can only create a parent and child records using one method but not to update both. You need to explicitly call update for Order item:

await Cupon.update({
  afiliado_id: afiliadoId,
  status: 'validado'
}, {
 where: {
   id: cupom.id
 }
})
await item.addCupons(cupom.id)

through option is applicable for many-to-many relationships only.

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!