How to execute a query with a list of identifiers in the JS Bookshelf

How can I get a list of PK entries in a single request using ?

The final query should be equivalent to:

SELECT * FROM `user` WHERE `id` IN (1,3,5,6,7);
+6
source share
2 answers

This solution works:

AdModel
  .where('search_id', 'IN', [1, 2, 3])
  .fetchAll();

You can also use Knex QueryBuilder to get the same result.

AdModel
.query(qb => {
    qb.whereIn('search_id',  [1, 2, 3]);
})
.fetchAll();
+11
source

List (single) query and select relationships (withRelated)

BookshelfModel
  .where('field_id', 'IN', [1, 2, 3])
  .fetchAll({withRelated: ["tableA", "tableB"]});
0
source

All Articles