在WHERE过滤器上使用OR条件查找StrongLoop Loopback模型 [英] StrongLoop Loopback Model find with OR condition on WHERE filter

查看:599
本文介绍了在WHERE过滤器上使用OR条件查找StrongLoop Loopback模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用StrongLoop的Model.find语法的名称或标识符来找到一个人(文档在这里: http://apidocs.strongloop.com/loopback/#modelfindfilter-callback )。



但我无法弄清楚指定OR条件。

我可以使用以下语法匹配名称和标识符:

$ pre > person.find({
其中:{
'name.text':{like:'Dave'},
'identifier.value':{like: '3303927'}
}
},callback);

但是我希望能够匹配名字OR标识符,像这样:

  person.find({
其中:{
'name.text':{like:'Dave'} ||
'identifier.value':{like:'3303927'}
}
},callback);

这个不支持,或者我无法得到正确的语法。看来这是通过REST API支持的(doc: http:/ / /docs.strongloop.com/display/DOC/Model+REST+API#ModelRESTAPI-Findmatchinginstances ),所以我希望这是我试图完成它的方式支持。



谢谢!

解决方案

最近添加了AND / OR运算符。请参阅使用示例:

https://github.com/strongloop/loopback-datasource-juggler/blob/master/test/basic-querying.test.js#L156





  person.find({
其中:{
或:{
'name.text':{like:'Dave'},
'identifier.value':{like:'3303927'}
}
}
},回调);


I'm trying to find a person by either their name OR identifier using StrongLoop's Model.find syntax (documentation here: http://apidocs.strongloop.com/loopback/#modelfindfilter-callback).

But I can't figure out how to specify the OR condition.

I can match both the name AND identifier using this syntax:

person.find({
    where: {
        'name.text': {like: 'Dave'},
        'identifier.value': {like: '3303927'}
    }
}, callback);

But I'd like to be able to match name OR identifier doing something like this:

person.find({
    where: {
        'name.text': {like: 'Dave'} ||
        'identifier.value': {like: '3303927'}
    }
}, callback);

Either this isn't supported or I can't get the syntax correct. It appears this is supported via the REST API (doc: http://docs.strongloop.com/display/DOC/Model+REST+API#ModelRESTAPI-Findmatchinginstances) so I'm hoping it's supported the way I'm trying to accomplish it.

Thanks!

解决方案

The AND/OR operator is added recently. Please see examples of usage at:

https://github.com/strongloop/loopback-datasource-juggler/blob/master/test/basic-querying.test.js#L156

The syntax is:

person.find({
    where: {
      or: {
        'name.text': {like: 'Dave'},
        'identifier.value': {like: '3303927'}
      }
    }
}, callback);

这篇关于在WHERE过滤器上使用OR条件查找StrongLoop Loopback模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆