-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
From the docs https://loopback.io/doc/en/lb3/Fields-filter.html ( it's the same for LB4), filter fields can be set to true/false in a query to include/exclude model properties. fields works with API Explorer and Node. But it couldn't set properties to false (exclude) via url.
Current Behavior
For example, model Order has three properties: id, name, and price. To exclude the name property from the result, as the docs suggested, the query can be written as ?filter[fields][name]=false. But it returns:
[{name: 'order 1'}, {name: 'order 2'}..]
i.e it includes only the name property instead. I checked the filter sent to the controller, it shows that the filter is being converted to
{fields: { name: 'false'}} // string
while with API Explorer, the filter is converted to
{fields: { name: false}} // boolean
The wrong type might cause the problem.
In order to make it work with urls, the query needs to be set as ?filter[fields][id]=true&filter[fields][price]=true
The issue might relate to #2208
Expected Behavior
fields should be able to exclude properties by setting properties to false via url just like what API Explorer/Node does.
Acceptance
-
checkwhereclause if it has the same issue ( see this). - fix it so that API Explorer/Node/url all have the same behavior
- add tests to check the filter that is sent to the controllers
- fix docs in
LB4/Working-with-data/fields-filterpage - Based on the code, it seems accept arrays
{fields: ['foo', 'bar']}. Check if array works for fields. Add proper normalization and error checking if needed. (explained in comment Failed to exclude properties by setting false infieldsfilter via url #4992 (comment))