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

112
Visualizações
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
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