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

111
Vistas
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 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