How to update all resulting models from a BookshelfJS collection?
bookshelf.js
Solution
I think if you want to update this way, you might want to try this:
Product
.where({sold_out: true})
.save(
{sold_out: false},
{method: 'update', patch: true}
)
Problem
Given for example, a list of products with an attribute of sold_out, I would like to update a field of every item in that collection. In this particular example, let's suppose I want to set the field `sold_out = false` to all items with that field set as `true`: ``` Product.where({sold_out: true}) .fetchAll() .then(soldOutCollection => { return Promise.all(product => { return product.save({sold_out: false}) }) }) ``` This works, but it triggers one query per item in the collection. Is there any way to update all items at once (triggering just one query)? PS: I'm trying to avoid using knex.js directly