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

support filtering by (non-)existing relationships #551

Closed
maurei opened this issue Aug 29, 2019 · 5 comments · Fixed by #792
Closed

support filtering by (non-)existing relationships #551

maurei opened this issue Aug 29, 2019 · 5 comments · Fixed by #792

Comments

@maurei
Copy link
Member

maurei commented Aug 29, 2019

Description

In #548 support for filtering by (non)-null to one relationships was added: /children?filter[parent.id]=isnull. As discussed in that issue, ideally we would like to allow to filter without having to reference the primary key.

To that end, we want to support filtering by (non)-existing relationships by using something like this:

  1. /children?filter[parent]=isnull for to one relationships
  2. /parents?filter[children]=isnull for to many relationships

Note that when dealing with to many relationships, isnull might not be the most intuitive choice from a semantic point of view, because in C#/EF a to-many relationship is a IEnumerable which can be empty but is usually never null. For the latter we could therefore consider to introduce eg. isempty or isset, and for consistency we could use the same in the case of to one.

@wisepotato
Copy link
Contributor

an IEnumerable can be empty...

I agree, isempty is more semantically correct. Any info on how this would be handled in jsonapi?

@maurei maurei changed the title support filtering by (non)-existing relationships support filtering by (non-)existing relationships Aug 30, 2019
@sk-pub
Copy link
Contributor

sk-pub commented Aug 30, 2019

I would say that filtering by parent and by children are different tasks.
Currently, I can't imagine a popular case when you need to find parents without children.

Also, 'isEmpty' and 'hasAny' sound more natural for a collection.

@maurei
Copy link
Member Author

maurei commented Aug 30, 2019

I consider them to be analogous: one is filtering by the (non-)existence of a to-one relationship and the other is doing the same for to-many relationships. Why do you think that there would inherently be less popular usecases for filtering by to-many relationships?

@sk-pub
Copy link
Contributor

sk-pub commented Aug 30, 2019

From the JADNC point of view the cases are kind of similar. But field types are different: a single object and a collection of objects.

Filtering by the parent is very popular: get the list of subfolders, get posts made by the user, get settings for the project, etc.

Filtering by children is rarer. It may be useful in some data processing or report building tools to find, let's say, jobs that have no applicants, or empty workspaces. It's hard to imagine something like this in a simple web/mobile application (a typical consumer of JSON API). Data processing tools, due to performance reasons, use direct storage access.

@wisepotato
Copy link
Contributor

@unicrus i can have multiple children, only one child, and multiple parents, and only one parent. It is very similar. It is just not in your use case.

What you consider a parent is just a relationship. If we are to support your use case we are first going to consider a more generic approach so it can be applied to more usescases, therefore helping more people.

I like to filter by children, maybe I want to find all leaves in a graph? This would require me filtering on all items that don't have children.

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

Successfully merging a pull request may close this issue.

3 participants