Skip to content

fix(laravel): preserve eager relation callback unions - #452

Open
shuvroroy wants to merge 6 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/l59-eager-relation-callbacks
Open

shuvroroy wants to merge 6 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/l59-eager-relation-callbacks

Conversation

@shuvroroy

Copy link
Copy Markdown
Contributor

withWhereHas() invokes its constraint with a related builder for the existence query and a relation for eager loading. Callback inference previously retained only the builder. Preserve the terminal instantiated relation alongside the model's custom builder, including through fluent calls, dotted paths, and explicit Builder|Relation hints. Apply the same inference to withWhereRelation().

The shared relation-chain resolver now retains the terminal relation and binds its declaring model to the fresh instance used for eager loading. It iterates path segments without collecting them and avoids fully resolving the final model merely to retrieve its name. Ordinary relation constraints still receive their related builder.

Adds type assertions, completion and diagnostic regressions, invalid-path tests, Laravel demos, and runtime assertions for both callback invocations. All audit expectations are now active. Removes completed L59 from the backlog.

Stack: depends on #451 (L58), above #450, #449, #448, and #447. This stacked PR targets upstream main, so its diff includes the unmerged dependencies. The final commit contains L59; merge the dependencies first.

Validation: full cargo test, both required clippy runs, cargo fmt --check, PHP syntax/runtime assertions, and Laravel analysis with exactly its three intentional diagnostics.

Framework observation: Laravel 13.24 strips :columns for the withWhereHas() existence query but retains the suffix in the eager-load key when a callback is provided. PHPantom's callback inference follows Larastan's stripped relation lookup; the runtime suffix assertion verifies the existence phase. Recommend a separate Laravel issue for the eager-load key behavior.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.12903% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/type_engine/variable/closure_resolution.rs 94.28% 8 Missing ⚠️
...engine/variable/forward_walk/callable_inference.rs 97.56% 2 Missing ⚠️
src/virtual_members/laravel/builder.rs 98.38% 1 Missing ⚠️
src/virtual_members/laravel/relationships.rs 95.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants