Skip to content

Infer dynamic where calls and relation-forwarded model scopes - #1329

Open
hemreduru wants to merge 1 commit into
dedoc:mainfrom
hemreduru:fix/dynamic-where-and-relation-scopes
Open

hemreduru wants to merge 1 commit into
dedoc:mainfrom
hemreduru:fix/dynamic-where-and-relation-scopes

Conversation

@hemreduru

Copy link
Copy Markdown
Contributor

Fixes #1324

Problem

When a query chain contains a dynamic where{Column}() / orWhere{Column}() call on an Eloquent Builder or a model scope called through an Eloquent Relation (e.g., $user->posts()->published()->paginate()), EloquentBuilderExtension::getMethodReturnType() returns null. Because unresolved method calls resolve to NeverType, subsequent calls in the chain (such as paginate()) also resolve to never, causing paginated resource collections to lose their links and meta pagination envelope in the generated OpenAPI specification.

Solution

  1. Dynamic where / orWhere calls on Builder: Return the current builder instance when a where{Column} or orWhere{Column} call (that is not an explicit Builder method) is invoked on a Builder.
  2. Model scopes forwarded through Relation: In forwardRelationCallToRelatedModelBuilder(), delegate method return type resolution to $builderType->getMethodReturnType(...) (which already runs EloquentBuilderExtension for the related model's builder, including local scopes and dynamic where calls) instead of bailing out early when the method is not directly defined on the builder class, and return null only if the resolved return type is UnknownType or NeverType.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Successfully merging this pull request may close these issues.

[Bug]: Paginated collection loses links/meta after a dynamic where{Column}() or a relation scope

2 participants