Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loopback Find() "where" clause not returning expected results

I am using loopback to serve the API for my application and I tried to change the GET request for some data.

As of now the query fetches all the results for a particular API:

People.find({
    where: {
      'town': 'name of a town'
    }
  }).$promise
  // Promise is fulfilled and people returned
  .then(function(results) {
    $scope.people = results;
  })
  // Promise is rejected and error catched
  .catch(function(err) {
    $scope.errors.PeopleFind = JSON.stringify(err.data.error.message ?
      err.data.error.message :
      err.data.error.errmsg
    );
  }); 

I already tried with adding single quotes to the where clause or to do something like .find({ where : { town : 'name of a town' }}.

No matter where I put the quotes the results are always the whole package. How would I query for just the results that I'm interested in?

Thanks in advance

like image 456
404answernotfound Avatar asked Nov 30 '25 11:11

404answernotfound


1 Answers

I found the answer thanks to a collegue, I'll write here the answer


People
            .find({
                filter: {
                    where: {Town : currentUserTown}
                }
            })

The documentation for the loopback framework did not state that you needed to apply a filter object to actually filter the results, in fact you can check the documentation with this example they wrote:

Cars.find({where: {carClass:'fullsize'}});

Before the where clause object you need to write the filter object that contains the clause, that should solve the problem with the query.

like image 192
404answernotfound Avatar answered Dec 02 '25 01:12

404answernotfound



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!