Repository navigation
Filter conditions: ?field[neq]=x, ?field[empty]=1, ?field[not_empty]=1, ?field[contains]=x - #35
Merged
Merged
Conversation
A filterable field still filters on equality with a plain parameter (?name=Foo). An array picks the operator: ?name[op]=contains&name[value]=Foo, ?url[op]=not_empty. FilterOperator maps the request names to the operators a QueryAdapter receives (catlab/base EQ, NEQ and SEARCH, plus new EMPTY and NOT_EMPTY). An unknown operator, or one without the value it needs, filters nothing. RequestResolver transforms only the value of such an array. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WpWbf8G82YF31PfRq1ggTi
Replaces the field[op]/field[value] shape from the previous commit, after review: one parameter per condition, so several combine (a range later) and JSON:API reads filter[status][neq]=sold. - An unknown condition, or one the field does not allow, throws InvalidFilterException (400) instead of silently returning everything. - contains only on searchable() fields; a searchable-only field only searches. - A list (?status[]=a) is passed on with the plain operator, as before. - Entity filter<Name>() methods only get NEQ/EMPTY/NOT_EMPTY when the entity implements FiltersWithOperators; otherwise the condition is refused, since such methods may ignore the operator. - FilterCollection::getFromName()/getFromDisplayName() only return an EQ or SEARCH filter, so a policy checking 'owner is me' cannot be fooled with owner[neq]=me; getAllFromName() returns every filter on a field. - Transformers run on each compared value, not on empty/not_empty/contains. - The OpenAPI filter description names the conditions. - conflict with charon-laravel <1.13, which would run EMPTY as col = 'EMPTY'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WpWbf8G82YF31PfRq1ggTi
Replaces the FiltersWithOperators marker interface (Thijs' suggestion): a filter<Name>() method whose second parameter is typed ConditionFilter (a new subclass of Filter, found with reflection) gets the filter object for every operator: filter<Name>($query, ConditionFilter $filter, $context, $entityClass). A method with the old ($query, $value, $operator, ...) signature keeps getting = and SEARCH; NEQ / EMPTY / NOT_EMPTY on its field are refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WpWbf8G82YF31PfRq1ggTi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Thijs · project thread
First of a chain of four (charon → charon-laravel → laravel-table → laravel-charon-frontend) so the catlab-events admin can list e.g. every event whose
event_urlis filled in.Syntax
A plain parameter still filters on equality (
?name=Foo), and a list (?status[]=a) is passed on as before. A condition is an array key, one parameter per condition, so several combine:?name[eq]=Bolt?name=Bolt?name[neq]=Bolt?name[contains]=olsearchable()fields?url[empty]=1/?url[not_empty]=1''/ the oppositeWith JSON:API:
filter[status][neq]=sold.Safety (from the review)
InvalidFilterException, which is anInputDataExceptionand becomes a 400 in charon-laravel.filter<Name>()method whose second parameter is typedConditionFilter(new subclass ofFilter, detected with reflection) gets the filter object for every operator:filter<Name>($query, ConditionFilter $filter, $context, $entityClass). A method with the old($query, $value, $operator, …)signature keeps getting=andSEARCH, and NEQ / EMPTY / NOT_EMPTY on its field are refused. Old methods may ignore$operator; Eukles'Event::filterTypeStringwould return X for "is not X".FilterCollection::getFromName()/getFromDisplayName()return only an EQ or SEARCH filter, so a policy checking "owner is me" can't be fooled byowner[neq]=me.getAllFromName()returns every filter on a field.empty,not_emptyorcontains.conflict: charon-laravel <1.13: the old adapter would turn EMPTY intocol = 'EMPTY'and return nothing.docs/050-filters.md.Tests
tests/FilterOperatorTest.php; full suite 153 tests OK locally. TheConditionFilteropt-in is covered by integration tests in charon-laravel#9: one method that takes aConditionFilterand one with the old signature.Release
Suggested tag v1.13.0.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WpWbf8G82YF31PfRq1ggTi