Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New filter for [not] null #257

Open
wolfgang42 opened this issue Feb 22, 2017 · 2 comments
Open

New filter for [not] null #257

wolfgang42 opened this issue Feb 22, 2017 · 2 comments

Comments

@wolfgang42
Copy link
Contributor

I have a need to filter a field for items which are not null. However, there is currently no filter syntax for either null or not null items. I can submit a pull request to add this feature, but I'm not sure what a suitable syntax is. I have thought of either filter[field]=*exists or filter[field]=!*null (adding the ! syntax for all filters, not just *null), but would like to seek feedback on this before implementing it.
Which syntax is preferred (or should we use something else altogether)?

@BryanHunt
Copy link

I just encountered this and it's now blocking me. I need to find objects where a relationship does not exist.

@wolfgang42
Copy link
Contributor Author

I wound up building my own custom filter handling, overriding jsonapi-server's filtering entirely (for various reasons not entirely to do with limitations of this library), so I won't be contributing a PR for this as I originally stated. However I still think it is a useful feature to have.

Here's the syntax I settled on:

filter[field]=value
filter[field][exists]=true
filter[field][in]=["value1","value2"] // JSON-encoded array

This has the advantage that it's A) easily extendable, and B) doesn't require any special escaping.

Also, I haven't needed it yet but you could easily add a [not] filter:

filter[field][not]=value
filter[field][not][in]=[1,2,3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants