Loopback.io多个包含模型查询条件

对于单个模型查询,我们可以对查询中定义的条件应用条件运算,其中和运算符应用于以下一系列条件:

{ where: {<and|or>: [condition1, condition2, ...]}} 

有没有一个简单的方法来应用包含在include中的模型的条件操作?

举个例子:

 Model.find({ include: [ { relation: "relation1", scope: { where: { condition1 } } }, { relation: "relation2", scope: { where: { condition2 } } }, ... ] }); 

是否可以在上面的条件1,条件2上应用和/或操作,即返回所有模型,使其与所包含模型的范围中定义的条件相匹配。

我相信你可以按照这个代码示例来做到这一点:

 Post.find({ include: { relation: 'owner', // include the owner object scope: { // further filter the owner object fields: ['username', 'email'], // only show two fields include: { // include orders for the owner relation: 'orders', scope: { where: {orderId: 5} // only select order with id 5 } } } } }, function() { ... }); 

这里logging了包含filter