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

$and and $or restricted filters are not forced when using relations #24

Open
ItsReddi opened this issue Nov 8, 2023 · 1 comment
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ItsReddi
Copy link
Contributor

ItsReddi commented Nov 8, 2023

Request

?filters[field1][$eq]=<value1>
&filters[$and][0][relationName][fieldX][$eq]=<valueX>
&filters[$and][1][relationName][fieldY][$eq]=<valueY>

Config

BaseModel (Where filters are applied to) has the following $filters

protected array $filters = [
        EqualFilter::class,
        NotEqualFilter::class,
        AndFilter::class,
        OrFilter::class,
    ];

The Relation model has:

protected array $filters = [
        EqualFilter::class,
        NotEqualFilter::class,
    ];

Result

Even if not defined in Relation model. The $and and $or filters are applied.

Also the other way around, if we do not apply and & or filters to base model but on relation model, the above query will not filter with $and. It is also not possible to change the request for that case to:

?filters[field1][$eq]=<value1>
&filters[relationName][$and][0][fieldX][$eq]=<valueX>
&filters[relationName][$and][1][fieldY][$eq]=<valueY>

Expected

Filter restrictions are applied, when working with relations

@abbasudo
Copy link
Owner

abbasudo commented Nov 8, 2023

Hello, thanks for your clear report. unfortunately, this is true for any relation filter. in this, line purity iterates throw the filter and as long as it finds some valid filter it returns. this behavior is correct as long as we don't have any relation filter.

the validate function should be changed to something like this function which considers the model.
any idea how to do this?

@abbasudo abbasudo added bug Something isn't working help wanted Extra attention is needed labels Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants