Skip to content

fix(laravel): infer relation callbacks from argument types - #453

Open
shuvroroy wants to merge 7 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/l60-relation-callback-arguments
Open

shuvroroy wants to merge 7 commits into
PHPantom-dev:mainfrom
shuvroroy:fix/l60-relation-callback-arguments

Conversation

@shuvroroy

Copy link
Copy Markdown
Contributor

Relation callbacks lost their related model when the relation came from a variable, a union of names, or a relation object. Complete L60 by resolving the argument through the shared type engine and retaining each related model's custom builder. Apply the same inference to relation shortcuts and direct Builder::with() callbacks.

Reuse the existing argument binder, cached relation-chain resolver, and ancestor template projection. Custom relation subclasses can reorder or fix their generic parameters; eager callbacks preserve concrete relations, and morph callbacks retain their second parameter. Unknown eager names keep the declared callback type.

Adds 19 type assertions (113 total), 13 completion/diagnostic cases with positive and negative member checks, navigation tests, Laravel demos, and 13 runtime checks (217 total). The fixture includes Laravel's separate static Model::with($relations) declaration; the direct two-argument callback form is tested through query()->with() to match runtime behavior.

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

Validation: full cargo test (14,837 passed), cargo clippy --fix --allow-dirty -- -D warnings, cargo clippy --all-targets -- -D warnings, cargo fmt --check, PHP syntax/runtime checks, and Laravel analysis with exactly the three intentional diagnostics.

Complete L60 by resolving relation-name variables, unions, and relation objects through the shared type engine. Retain custom builders for relation shortcuts and concrete relations for direct eager callbacks.

Cover callback types, completion, diagnostics, navigation, and Laravel runtime behavior. Keep this follow-up separate from L59.
@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.56160% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/type_engine/variable/closure_resolution.rs 94.91% 9 Missing ⚠️
...engine/variable/forward_walk/callable_inference.rs 98.80% 1 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!

This branch has not been deployed

No deployments
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