-1

Currently i have done code to accept one category_id in the param and return output base on category_id.

if ('category' in params) {
        assert.number(params.category, 'params.category')

        const { category: category_id } = params
        query = query.where('category.id', category_id)
      }

Now i want to pass multiple values to category_id and return result for all category_id's.

I will pass like this, category_id=1,2,3

Can someone helps me to fix this?

2 Answers2

0

http://knexjs.org/#Builder-whereIn

query.whereIn('category.id', [1, 2, 3]);
0

Improve Ростислав Борніцький answer little bit,

if ('category' in params) {
        assert.array(params.category, 'params.category')

        const { category: category_id } = params
        query = query.whereIn('category.id', category_id)
      }