bookshelf.js:如何将updatePivot与查询一起使用

时间:2015-10-15 00:54:46

标签: bookshelf.js

我正在使用:

.updatePivot({sort_order:2}, [some query goes here])

如何格式化查询以便只更新连接表中查询的行?我试过了:

.updatePivot({sort_order:2}, { where: {tagId: 117} })

但是仍然为表中的所有行设置sort_order为2,而不仅仅是tagId = 117的行。

1 个答案:

答案 0 :(得分:4)

updatePivot的文档说options参数是选项的哈希值。所以你需要将其指定为

.updatePivot({sort_order:2}, { query: { where: {tagId: 117} } })
另外,我相信你可以做点什么

.forge({tagId: 117}).related('b2m relationship').updatePivot({sort_order: 2})