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

Filtering inlcuded resources #286

Open
LucindaX opened this issue Jun 5, 2024 · 1 comment
Open

Filtering inlcuded resources #286

LucindaX opened this issue Jun 5, 2024 · 1 comment

Comments

@LucindaX
Copy link

LucindaX commented Jun 5, 2024

I'm trying to filter the resources included on my request.

To give an example :

I have two models, a User and Posts.

/api/v1/users/123?include=posts&filter[posts][approved]=true

The above query would filter the users that have approved posts and return them, but would still return all posts on the relationship ( approved or otherwise ).
Assuming the usage of a WhereHas or a Where filter on the UserSchema.
This makes sense though, as I'm querying the users resource.

What I would actually like to do is :

A user has many posts, I want to query user "X", including their posts, but only approved posts.

From the documentation, filtering includes does not seem to be available.
I thought about having a custom filter, but I am a bit lost on how that would work.

Something like filter[included][posts][approved]=true to distinguish that it's a filter applied to the included resource maybe. And an Included::make('posts') filter that would rely on the filters defined on the PostSchema

OR

The query can be left as it is filter[posts][approved]=true and the filter would be something along the lines of IncludedWhere which would apply the filter to the included resource if requested, if not, it would act as a normal Where filter ... this looks cleaner to me and leaves the specification on the schema rather than complicate the query params.

@lindyhopchris
Copy link
Contributor

Hey. Filtering includes is not supported. It's unlikely to be supported any time soon, because it is hideously complicated. It's not a simple as adding a new filter class, because we would need to apply the filter as we're doing the eager loading - which is done separately.

We do need to refactor the eager loading at some point, so it might be possible to add support for it then. That's going to be a complex bit of work, so isn't likely to happen soon.

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

No branches or pull requests

2 participants