Repository navigation
Fix: allow enum filters on relation queries - #8
Merged
Merged
Conversation
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.
Problem
Applying
EnumFilterorEnumBooleanFilterto a resource index rendered through a relation (e.g. aHasManyfield on a detail page) throws:Root cause
Nova may hand the filter an
Illuminate\Database\Eloquent\Relations\Relationinstead of a plainBuilder.Relation::__call()forwardswhere()/whereIn()to the inner builder viaforwardDecoratedCallTo(), which returns the relation itself, so the filter returns aHasMany, violating the: Builderreturn type.Both classes implement
Illuminate\Contracts\Database\Eloquent\Builder, the same type Nova's ownFilter::apply()documents.Fix
Return type widened from the concrete Eloquent builder to the contract it shares with relations. Two-line diff, behavior unchanged:
applied to
src/EnumFilter.phpandsrc/EnumBooleanFilter.php.Verification
TypeErroron aHasManyrelation before the fix; after the fix both filters apply cleanly onBuilderandHasMany, an empty boolean selection stays a no-op, and the generated SQL is unchanged.php-cs-fixer --dry-runwith the repo config: clean.