只有 1 orWhere in Bookshelf 查询?

Only 1 orWhere in Bookshelf query?

我的控制器中有以下 Bookshelf 方法:

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();

但是,它似乎不适用第二个 orWhere,并且只适用 returns 个状态匹配“已付款”或“已结算”的实例。可能不允许在查询中使用第二个 orWhere 吗?什么是更好的语法?

您可以使用查询回调:

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