Skip to content

feat(router): preload model relations during route binding#2232

Merged
brendt merged 2 commits into
tempestphp:3.xfrom
xHeaven:feature/with-relations-route-binding
Jul 22, 2026
Merged

feat(router): preload model relations during route binding#2232
brendt merged 2 commits into
tempestphp:3.xfrom
xHeaven:feature/with-relations-route-binding

Conversation

@xHeaven

@xHeaven xHeaven commented Jul 20, 2026

Copy link
Copy Markdown
Member

Closes #2110.

@xHeaven
xHeaven force-pushed the feature/with-relations-route-binding branch from 8232333 to c795cb9 Compare July 20, 2026 10:52
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

Benchmark Results

Comparison of feature/with-relations-route-binding against 3.x (dae32bb2a607df2fac7c755a8f6344ea4bf8af84).

Open to see the benchmark results

No benchmark changes above ±5%.

Generated by phpbench against commit 3cd214f

@brendt

brendt commented Jul 20, 2026

Copy link
Copy Markdown
Member

Looks good to me. One edge case I wonder about: \Tempest\Router\Bindable::resolve still has one parameter. That's fine, we don't break LSP by adding one more in the IsDatabaseModel trait. However, shouldn't we check whether the current resolve implementation within our RouteBindingInitializer actually accepts the relations?

I guess PHP will simply ignore the additional parameter if it's not present, so I guess we're good. Just wanted to double check if I hadn't missed anything

@xHeaven

xHeaven commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

Looks good to me. One edge case I wonder about: \Tempest\Router\Bindable::resolve still has one parameter. That's fine, we don't break LSP by adding one more in the IsDatabaseModel trait. However, shouldn't we check whether the current resolve implementation within our RouteBindingInitializer actually accepts the relations?

I guess PHP will simply ignore the additional parameter if it's not present, so I guess we're good. Just wanted to double check if I hadn't missed anything

Good catch. Usually PHP would ignore the additional parameter. However, it's a named one, so that will throw. I'm not yet sure what we should do about this - making it unnamed feels a bit weird. What do you think would be good here?

@brendt

brendt commented Jul 21, 2026

Copy link
Copy Markdown
Member

Well… it would only call the method with named parameter if the attribute was provided.

Can we wrap this in an exception that clearly explains what's wrong? (eg. "You added preload to a class that doesn't use IsDatabaseModel").

It's a bit dirty, but I feel it's good enough for now

@brendt
brendt merged commit 46e1c86 into tempestphp:3.x Jul 22, 2026
76 checks passed
@brendt

brendt commented Jul 22, 2026

Copy link
Copy Markdown
Member

Perfect :)

@xHeaven
xHeaven deleted the feature/with-relations-route-binding branch July 22, 2026 08:18
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.

preload relations when resolving route model bindings

2 participants