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

Does this work with Collections? #2

Closed
JSmythSSG opened this issue Jul 23, 2021 · 3 comments
Closed

Does this work with Collections? #2

JSmythSSG opened this issue Jul 23, 2021 · 3 comments

Comments

@JSmythSSG
Copy link

When I try to filter with nested collections it doesn't seem to return correct amount.

If I try or[contact.id]=11&or[assigned.engineer.id]=44

the count should be 400 but it returns 10 as the inner join on the one to many seems to limit it

@jarrodirwin
Copy link

@JSmythSSG Did you ever get this working with nested collections?

@metaclass-nl
Copy link
Owner

metaclass-nl commented Dec 1, 2021

Sorry for the late response.

Looks like SearchFilter did not expect to be used with nested collections in combination with OR. This is strange because IMHO leaving adding of the where expressions to the implementation of FilterInterface::apply suggest implementors may choose for themselves between using ::andWhere or ::orWhere on the QueryBuilder. Given the implementation of these methods later calls will put the expressions from previous calls in parentheses, so if the custom filter is applied after a SearchFilter, this is what will happen.

And the documentation on Filters does not state that the use of ::andWhere is required. So I guess this could be considered a bug of SearchFilter (the other filters that support nesting may contain the same bug). But issue 826 is about a similar problem, it seems in this comment Antoine Bluchet describes the policy that nullable associations should be LEFT joined. But contrary to this, in this comment Teoh Han Hui says the behavior is correct and the issue is closed.

But in issue 639 the problem is also mentioned and that issue is still open. It also refers to an example in this gist. But as long as the built-in filters of Api Platform generate inner joins for properties nested over nullable or and to many associations, entities that are not associated with at least one related entity will not show up, combining them with OR can not change that. So if they want have (an) OR filter, they must reconsider issue 826. As long is they do not close issue 639 i consider the inner joins a bug.

BTW, one to many relationships are not mentioned explicitly in any of these issues and i could not find an issue that does.

metaclass-nl added a commit that referenced this issue Dec 18, 2021
- added two workarounds
- adapted tests
- adapted readme
@metaclass-nl
Copy link
Owner

I added two workarounds for the problem that the built-in filters of Api Platform generate inner joins for properties nested over nullable or and to many associations. But because the are quite intrusive and for reasons of backward compatibility you have to activate them explicitly, see the readme under "Nested properties workaround".

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

3 participants