Repository navigation
Add @whereDoesntHaveConditions directive - #2829
officialasishkumar wants to merge 1 commit into
Conversation
`@whereHasConditions` lets clients filter a query by the existence of
related models that match dynamic conditions, but there was no
counterpart to filter by their absence. Excluding records related to a
given model while keeping records without any related models required
letting clients build `HAS` conditions with `operator: LT` and
`amount: 1` through `@whereConditions`, with a client-controlled
relation name.
`@whereDoesntHaveConditions` works like `@whereHasConditions`, but
constrains the relation with `< 1` instead of `>= 1`, which Eloquent
turns into `NOT EXISTS`, just like `whereDoesntHave()`. It supports the
same `relation`, `columns`, `columnsEnum` and `handler` arguments and
infers the relation from argument names following the convention
`doesntHave{$RELATION}`. Passing an empty object filters for models
without any related model, `null` leaves the query unchanged.
Resolves nuwave#1646
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The failing |
Resolves #1646
Changes
Adds
@whereDoesntHaveConditions, the counterpart of@whereHasConditionsthat filters a query by the absence of related models matching client given conditions.{ people(doesntHaveProjects: { column: ID, value: 5 }) { name } }This returns every person who is not related to the project with ID 5, including people without any project.
An empty object returns only models without any related model,
nullleaves the query unchanged.The directive extends
WhereHasConditionsDirectiveand supports the samerelation,columns,columnsEnumandhandlerarguments.It infers the relation from argument names following the convention
doesntHave{$RELATION}and generates input types with the suffixWhereDoesntHaveConditions.It passes the conditions on as a
HAScondition withoperator: <andamount: 1, which Eloquent turns intoNOT EXISTS, just likewhereDoesntHave().With dot notation such as
relation: "user.company", it excludes posts whose user has a company that matches the conditions.Custom handlers receive the same
HASstructure that clients could already send through@whereConditions.To share the logic,
WhereHasConditionsDirectivegets two small protected hooks for the relation name prefix and the amount operator.Breaking changes
None.
Changelog
Added
@whereDoesntHaveConditionsdirective to filter a query by the absence of related models matching dynamic conditions