Skip to content

Commit 6f7d0ff

Browse files
committed
docs(database): update query() docs to reflect all relation types now supported
1 parent 3b5e132 commit 6f7d0ff

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

docs/1-essentials/03-database.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,13 +776,21 @@ $author->query('books')->update(title: 'Updated')->execute();
776776
$author->query('books')->delete()->execute();
777777
```
778778

779-
The `query()` method works with `HasMany`, `HasManyThrough`, and `BelongsToMany` relations — any relation that returns a collection. Calling it on a singular relation like `BelongsTo` or `HasOne` will throw an exception.
779+
The `query()` method works with all relation types:
780780

781781
```php
782-
// HasManyThrough
782+
// HasMany / HasOne — simple FK on related table
783+
$author->query('books')->select()->all();
784+
$book->query('isbn')->select()->first();
785+
786+
// BelongsTo — subquery through owner's FK
787+
$book->query('author')->select()->first();
788+
789+
// HasManyThrough / HasOneThrough — subquery through intermediate table
783790
$tag->query('reviewers')->select()->all();
791+
$tag->query('topReviewer')->select()->first();
784792

785-
// BelongsToMany
793+
// BelongsToMany — subquery through pivot table
786794
$tag->query('books')->select()->all();
787795
```
788796

packages/database/src/BelongsTo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Tempest\Support\Arr\ImmutableArray;
1717
use UnitEnum;
1818

19-
use function Tempest\Database\query;
2019
use function Tempest\Support\str;
2120

2221
#[Attribute(Attribute::TARGET_PROPERTY)]

packages/database/src/HasOne.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Tempest\Support\Arr\ImmutableArray;
1717
use UnitEnum;
1818

19-
use function Tempest\Database\query;
2019
use function Tempest\Support\str;
2120

2221
#[Attribute(Attribute::TARGET_PROPERTY)]

packages/database/src/HasOneThrough.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Tempest\Support\Arr\ImmutableArray;
1717
use UnitEnum;
1818

19-
use function Tempest\Database\query;
2019
use function Tempest\Support\str;
2120

2221
#[Attribute(flags: Attribute::TARGET_PROPERTY)]

tests/Fixtures/Migrations/CreateBookTagTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use Tempest\Database\MigratesDown;
88
use Tempest\Database\MigratesUp;
9-
use Tempest\Database\QueryStatements\OnDelete;
109
use Tempest\Database\QueryStatement;
1110
use Tempest\Database\QueryStatements\CreateTableStatement;
1211
use Tempest\Database\QueryStatements\DropTableStatement;
12+
use Tempest\Database\QueryStatements\OnDelete;
1313

1414
final class CreateBookTagTable implements MigratesUp, MigratesDown
1515
{

tests/Integration/Database/Builder/IsDatabaseModelTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Tempest\Integration\Database\Builder;
66

7-
use BadMethodCallException;
87
use Carbon\Carbon;
98
use DateTime as NativeDateTime;
109
use DateTimeImmutable;

0 commit comments

Comments
 (0)