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;
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?
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)
}
})
})
})