Filtering array query params
See original GitHub issueSome clients (e.g. Ember) send requests like ?filter[tags][]=1&filter[tags][]=2
for the membership in a list of values (JSON API).
To process this kind of filter I only changed (https://github.com/django-json-api/django-rest-framework-json-api/blob/master/rest_framework_json_api/django_filters/backends.py#L66) from
^filter(?P<ldelim>\[?)(?P<assoc>[\w\.\-]*)(?P<rdelim>\]?$)
to
^filter(?P<ldelim>\[?)(?P<assoc>[\w\.\-]*)(?P<rdelim>\]?)(\[\])?$
Everything seems to work fine. What do you think?
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Nested Array to Query Params for Filters in Searching
You can make a loop through the array and use Object.key() with forEach function to get the property name and value. Share.
Read more >Array.prototype.filter() - JavaScript - MDN Web Docs
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given...
Read more >Filtering on related entries (with an array query param)
I'm getting myself into a potential pickle here and wanting to know the best way to get apply filters on the current scenario:...
Read more >Filter an array - Algolia
Go to your dashboard and select your index. · Click the “Add Query Parameter” button, which is just below the search bar. ·...
Read more >An array in Filter Query - Power Platform Community - Microsoft
Hi, I want to filter items using an array variable from another list. The query would be something like this: client eq 'a'...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The fact that Ember Data (specifically the JsonAPIAdapter) serializes arrays in the query parameters by adding empty brackets isn’t very well documented. A hint that this is the case can be found here: https://api.emberjs.com/ember-data/3.13/classes/JSONAPIAdapter/methods?anchor=findMany
The relevant code where the actual serialization takes place can be found here: https://github.com/emberjs/data/blob/v3.13.1/packages/adapter/addon/-private/utils/serialize-query-params.ts#L20
Even though this is not detailed out in the JSON API Specification I’d argue to consider the way Ember does this more or less the de-facto standard as there isn’t any other reference client side implementation of the JSON API specification. If not DJA should at least offer the option to handle query parameter lists the Ember way.
We only want to implement in DJA what is actually JSON API spec specific; otherwise such implementation need to happen in the respective upstream project (Django Filter, DRF or even Django itself). So a
allin
lookup is not DJA specific in this regard. And how DJA users use DjangoFilterSet is also up to them as JSON API spec doesn’t define how filter arguments are used. If you are referring to changes suggested in https://github.com/django-json-api/django-rest-framework-json-api/issues/718#issuecomment-605821483 I think that it is a good way forward to make the backend more powerful.