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 filter nested collection #216

Closed
MichaelKoch11 opened this issue May 31, 2022 · 6 comments
Closed

Support filter nested collection #216

MichaelKoch11 opened this issue May 31, 2022 · 6 comments
Labels
enhancement New feature or request invalid This doesn't seem right

Comments

@MichaelKoch11
Copy link

It would be a nice feature or I doest find it yet to filter nested collection.

Like in the Live Example to filter Company with

(id < 10 and employees.maritalStatus: "unknown")
curl -X 'GET'
'https://spring-filter.herokuapp.com/company?filter=id%20%3C%2010%20and%20employees.maritalStatus%3A%22unknown%22'
-H 'accept: /'

Expected Output

[
  {
    "id": 4,
    "name": "Huel Inc",
    "industry": {
      "id": 3,
      "name": "Capital Markets"
    },
    "employees": [
      {
        "id": 11,
        "firstName": "Johana",
        "lastName": "Crona",
        "birthDate": "13-09-1980",
        "maritalStatus": "unknown",
        "salary": 2301
      },
      {
        "id": 16,
        "firstName": "Cora",
        "lastName": "Lebsack",
        "birthDate": "18-10-1961",
        "maritalStatus": "unknown",
        "salary": 5783
      }
    ]
  }
]

In my own example with one Entity and 3 Elements in nested collection i got 3 times the same response

@ghulamemustafa
Copy link

This is the only limitation I have faced so-far in the project. Please support :)

@torshid
Copy link
Member

torshid commented Sep 2, 2022

Hey @MichaelKoch11 @ghulamemustafa

I think that this is out of the scope of the project. The goal is to apply filtering criteria to a collection (e.g. car table) in order to filter the elements of that specific collection (as it is with SQL queries).
Your query actually means get me the companies which have at least one employee which has the marital status 'unknown'.

In this specific case you could make a request to the employee API: employee?filter= company.id < 10 and maritalStatus : 'unknown', which will effectively only return employees with the marital status unknown.

If you have an idea on how we could achieve your requirement, I would be glad to hear that.

Also please do note that there are other pending issues, you can always sponsor me so that I can dedicate more time to feature requests.

Thank you.

@torshid torshid added enhancement New feature or request invalid This doesn't seem right labels Sep 2, 2022
@ghulamemustafa
Copy link

@torshid I am a little confused here on how is this out of the scope as we're unable to filter company based on its employes. Also the example you gave about employee API doesn't fulfil the orignal goal i.e filter company.

@torshid
Copy link
Member

torshid commented Sep 2, 2022

@ghulamemustafa I think that there is a misunderstanding here. @MichaelKoch11 wanted to filter employees of companies, not companies based on employees.

As I said earlier, the search query Michael shared is valid and correctly filters companies based on employees, but it does not apply a second filter to the employee collection (which is what he requested: get companies according to some criteria and filter the employees of these companies based on other criteria).

It would be nice if you can provide your search query and tell what you are trying to achieve exactly.

Thanks.

@ghulamemustafa
Copy link

I just realized that the confusion was on my side (my bad). I just want to filter the companies based on the employees attributes.
eg:
get me the companies which have at least one employee which has the marital status 'unknown'

@torshid
Copy link
Member

torshid commented Sep 13, 2022

@ghulamemustafa get me the companies which have at least one employee which has the marital status 'unknown' is equivalent to /company?filter= employees.maritalStatus : 'unknown'.

Closing the issue as the original request is out of scope.

@torshid torshid closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants