Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StrongLoop Loopback Model find with OR condition on WHERE filter

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!

like image 858
user1754286 Avatar asked May 20 '14 21:05

user1754286


People also ask

What is StrongLoop LoopBack?

LoopBack, an open-source Node application framework based on Express. StrongLoop Process Manager and related devops tools for Node applications.

Is LoopBack based on express?

LoopBack is a framework built on top of Express. It comes packed with tools, features, and capabilities that enables rapid API and microservices development and easy maintenance. In this post we will explore the points that make LoopBack a compelling choice for Express developers when it comes to API development.

What is model in LoopBack?

A LoopBack model is a JavaScript object with both Node and REST APIs that represents data in backend systems such as databases. Models are connected to backend systems via data sources. You use the model APIs to interact with the data source to which it is attached.


1 Answers

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);
like image 84
Raymond Feng Avatar answered Nov 09 '22 07:11

Raymond Feng