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

110
Views
Bookshelf.js - How does updatePivot() update each item with Different value?

Tables

There are three tables Sheets, SheetSongs and Songs;

Sheets and Songs are Many-to-Many Relationships

Table SheetSongs is a joinTable of the other two which contains a extra int column named order;

Question

I want to update order with different numbers when I attach songs to Sheets.

But I could only get results with same order.

How can I update Them with different Order via bookshelf.js? or only with loop via knex?

Here is my code

        await new Sheet({sheet_id}).fetch().then(async sheet => {
                let order = 0
                await sheet.songs().attach(song_ids)  //eg. song_ids = [1,2,3,4]
                    .then( async ()=> {
                        sheet.songs().updatePivot({order: order+1},{  
                            query: function (qb){
                                qb.whereIn("song_id", song_ids)
                            }
                        })
                })
        })
about 4 years ago · Juan Pablo Isaza
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!