Loopback has a particular interface for REST APIs. It allows you to write a query like so:
Model.find({where: {id: {inq: [1, 2, 3]}}})
However, this query is also valid: Model.find({where: {id: {inq: []}}}), but it will obviously not return any results.
In this case, the generated query looks like this:
http://localhost:3010/api/model?filter=%7B%22where%22%3A%20%7B%22id%22%3A%20%7B%22inq%22%3A%20%5B%5D%7D%7D%7D
and decoded, like this:
http://localhost:3010/api/model?filter={"where": {"id": {"inq": []}}}
The problem is inside http-invocation.js, line: 215.
// query is an object: query = {where: {id: {inq: []}}}
qs.stringify(query) //this will return an empty string
Querystring behaviour (from node REPL):
> qs.stringify({where: {id: {inq: [1]}}})
'where%5Bid%5D%5Binq%5D%5B0%5D=1'
> qs.stringify({where: {id: {inq: []}}})
''
>
If you are integrating another loopback API, when you do the query with an empty array, you expect to get back an empty collection of items, but instead, because of the behaviour of querystring, you get back all the items.
See related issues:
Loopback has a particular interface for REST APIs. It allows you to write a query like so:
Model.find({where: {id: {inq: [1, 2, 3]}}})However, this query is also valid:
Model.find({where: {id: {inq: []}}}), but it will obviously not return any results.In this case, the generated query looks like this:
and decoded, like this:
The problem is inside http-invocation.js, line: 215.
Querystring behaviour (from node REPL):
If you are integrating another loopback API, when you do the query with an empty array, you expect to get back an empty collection of items, but instead, because of the behaviour of querystring, you get back all the items.
See related issues: