Skip to content

feat(database): add option to get underlaying query for property relation#2102

Open
laylatichy wants to merge 29 commits intotempestphp:3.xfrom
laylatichy:feat-add-option-to-get-underlaying-query-for-property
Open

feat(database): add option to get underlaying query for property relation#2102
laylatichy wants to merge 29 commits intotempestphp:3.xfrom
laylatichy:feat-add-option-to-get-underlaying-query-for-property

Conversation

@laylatichy
Copy link
Copy Markdown
Contributor

@laylatichy laylatichy commented Apr 4, 2026

pr to add option to have similar behavior to laravels author->books() to get underlying query for property relation we can chain into

// select with constraints
$author->query('books')->select()->whereField(field: 'title', value: 'Timeline Taxi')->all();
$author->query('books')->select()->limit(limit: 5)->all();

// count
$author->query('books')->count()->execute();

// update scoped to relation
$author->query('books')->update(title: 'Updated')->execute();

// delete scoped to relation
$author->query('books')->delete()->execute();

works with all relation types:

// HasMany / HasOne
$author->query('books')->select()->all();
$book->query('isbn')->select()->first();

// BelongsTo
$book->query('author')->select()->first();

// HasManyThrough / HasOneThrough
$tag->query('reviewers')->select()->all();
$tag->query('topReviewer')->select()->first();

// BelongsToMany
$tag->query('books')->select()->all();

now, I wasnt sure about naming it but opted in for query since it returns querybuilder same as query() helper just scoped to model property

…cit attr, unsaved model, nonexistent property, empty result)
…e, return QueryBuilder for select/update/delete support
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

Benchmark Results

Comparison of feat-add-option-to-get-underlaying-query-for-property against 3.x (6c8b9fefdf1a7c7cde6cecdfe9ae902883cc05c7).

Open to see the benchmark results
Benchmark Set Mem. Peak Time Variability
ViewRenderBench(benchExpressions) - 24.517mb 0.00% 560.933μs +5.88% ±1.61% -28.58%

Generated by phpbench against commit ceec41c

@laylatichy laylatichy force-pushed the feat-add-option-to-get-underlaying-query-for-property branch from 6ca7341 to 6f7d0ff Compare April 4, 2026 03:24
@laylatichy laylatichy force-pushed the feat-add-option-to-get-underlaying-query-for-property branch from debbc8f to ceec41c Compare April 4, 2026 03:54
@laylatichy laylatichy marked this pull request as ready for review April 4, 2026 04:14
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.

1 participant