Skip to content

feat(database): forward query builder methods to database models - #2285

Open
osbre wants to merge 2 commits into
tempestphp:3.xfrom
osbre:feat/database-model-static-query-methods
Open

feat(database): forward query builder methods to database models#2285
osbre wants to merge 2 commits into
tempestphp:3.xfrom
osbre:feat/database-model-static-query-methods

Conversation

@osbre

@osbre osbre commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This PR introduces static select-side query builder methods to IsDatabaseModel, removing the redundant ::select() boilerplate when starting queries.

Before

Book::select()->whereField('title', 'Timeline Taxi')->first();
Book::select()->orderBy('published_at')->limit(10)->all();

After

Book::whereField('title', 'Timeline Taxi')->first();
Book::orderBy('published_at')->limit(10)->all();
Book::whereHas('author', fn ($q) => $q->whereField('name', 'Brent'))->all();

Changes

  • Forwarded 39 Select-Side Methods: Methods like where, whereField, whereHas, orderBy, limit, with, join, and pagination helpers can now be called directly statically on models. Each forwarder is a direct delegation to static::select()->....
  • Fixed Return Annotations: Updated HasWhereRelationMethods::whereHas() and whereDoesntHave() annotations to ensure proper type inference for the forwarded methods.
  • Excluded Methods: Chain-continuation methods (andWhere*, orWhere*) and internal SQL compilation utilities remain builder-only, since neither is meaningful as an opening call.

Tests

No new tests were added. Every forwarded method is already exercised at the builder level in tests/Integration/Database/, and the forwarders add no logic beyond method dispatch. This follows the existing convention of testing behaviour where the builder lives: the sum() and avg() statics are covered in AggregateQueryBuilderTest, not IsDatabaseModelTest.

@osbre

osbre commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Regarding the benchmark glitch: #2286

@innocenzi

Copy link
Copy Markdown
Member

Not something I am in favor of personally. select is explicitly creating the request, and it reads well.

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