Nick
Nick

Reputation: 3090

Only 1 orWhere in Bookshelf query?

I have the following Bookshelf method in my controller:

const transaction = await Transaction.query({
    where: { status: "paid", id: req.params.transaction_id },
    orWhere: { status: "settled", id: req.params.transaction_id },
    orWhere: { status: "PERFORMED", id: req.params.transaction_id },
}).fetch();

However, it doesn't seem to apply the second orWhere and only returns instances where the status matches "paid" or "settled". Is it perhaps not allowed to use a second orWhere in the query? What would be a better syntax?

Upvotes: 0

Views: 91

Answers (1)

Pipe
Pipe

Reputation: 2424

You can use a query callback:

Transaction.query(function (qb) {
    qb.where('key1', 'value1')
       .orWhere('key2', 'value2')
       .orWhere('key3', 'value3')
       .orWhere('key4', 'value4')
});

Upvotes: 1

Related Questions