Repository navigation
Honor overridden query() on instance calls to the model - #380
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
Description
Overriding
query()on a model only took effect for static calls such asUser::all(),User::first()andUser::paginate(). Instance calls such as$user->first()bypassed it. This is what happens when a model is injected into a controller method.Cause:
Model::__call()built its builder with$this->newQuery(), which creates anew Builder(...)directly. The staticquery()was never called, so the override was skipped.Fix:
Model::__call()now usesstatic::query($this->connection), so static and instance calls share one entry point.newQuery()is unchanged. Internal persistence (save, update, delete by key) still uses it, so aquery()override does not leak into writes.Behavior notes
query().query()builds a freshnew static(), so runtime changes made on the instance are ignored by dynamic calls. Examples are$model->setTable('other')followed by$model->where(...), or a per-instance$pageSize. Class-level$tableand$pageSizebehave as before.Testing
$user->first()in an injected controller method now applies thequery()override.Checklist