Skip to content

Commit c2fb99d

Browse files
committed
Document getNbPages() where the docs teach the page count
llms-full.txt labelled $page->total as the page count; it is the item count. The tutorial notes said the page count was unavailable.
1 parent 0ca907c commit c2fb99d

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

docs/ja/MediaQuery.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ interface UserListInterface
107107
}
108108
```
109109

110-
実行結果の`Pages`は、配列アクセスでページを取得したり`count()`で全体の件数を取得することができます
110+
実行結果の`Pages`は、配列アクセスでページを、`count()`で全体の件数を、`getNbPages()`で総ページ数を取得できます
111111

112112
```php
113113
$userList = $injector->getInstance(UserListInterface::class);
114114
$pages = $userList();
115115
$page = $pages[1];
116116
$total = count($pages);
117+
$nbPages = $pages->getNbPages();
117118
```

docs/llms-full.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Every row of this table is a valid return type on a `#[DbQuery]` method.
8484
| `AffectedRows` | UPDATE/DELETE | Exposes `->count` (int) and `->isAffected(): bool`. |
8585
| `InsertedRow` | INSERT | Exposes `->values` (resolved params) and `->id` (?string lastInsertId). |
8686
| custom `X implements PostQueryInterface` | SELECT or DML | Polymorphic dispatch — framework calls `X::fromContext($context)`. SELECT pre-hydrates rows on `$context->rows`; DML leaves `$context->rows = []`. |
87-
| `Pages` (with `#[Pager]`) | SELECT | Lazy paginator. Index access executes `LIMIT`/`OFFSET`; `count()` does `COUNT`. |
87+
| `Pages` (with `#[Pager]`) | SELECT | Lazy paginator. Index access executes `LIMIT`/`OFFSET`; `count()` does `COUNT`, and `getNbPages()` divides it by `perPage`. |
8888

8989
How dispatch is decided:
9090

@@ -400,10 +400,11 @@ interface ProductRepository
400400

401401
$pages = $repo->list();
402402
count($pages); // → COUNT query
403+
$pages->getNbPages(); // → number of pages, from the same COUNT (memoized)
403404
$page = $pages[1]; // → SELECT with LIMIT/OFFSET, rows hydrated to Product
404405
$page->data; // items
405406
$page->current; // int
406-
$page->total; // int (total pages)
407+
$page->total; // int (total item count)
407408
$page->hasNext; // bool
408409
$page->hasPrevious; // bool
409410
(string) $page; // rendered pager HTML

docs/reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,9 @@ interface ProductRepository
610610
}
611611

612612
$pages = $productRepo->getProducts();
613-
$count = count($pages); // COUNT query を実行
614-
$page = $pages[1]; // LIMIT/OFFSET 付き SELECT を実行
613+
$count = count($pages); // COUNT query を実行
614+
$nbPages = $pages->getNbPages(); // 総ページ数。件数を取ってceilする必要はない
615+
$page = $pages[1]; // LIMIT/OFFSET 付き SELECT を実行
615616

616617
// Page object properties:
617618
// $page->data // このページの item

docs/tutorial/README.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ first stats row=MyBlog\ArticleStats commentCount=2 excerpt='Updated body.'
13331333

13341334
### 解説
13351335

1336-
- `count($pages)`**総アイテム数** (= COUNT クエリの結果)。総ページ数ではないので注意
1336+
- `count($pages)`**総アイテム数** (= COUNT クエリの結果)。総ページ数は `$pages->getNbPages()` で取る (同じ COUNT を使い回す)
13371337
- `$pages[1]` でページ1にアクセス → SELECT に LIMIT/OFFSET が付いて実行される (lazy)。
13381338
- `$page->data` は Article のリスト (`@return Pages<Article>` のおかげで hydration が効く)。
13391339
- `#[DbQuery(factory: ArticleStatsFactory::class)]``#[Pager]` を併用した場合、1.1 以降は `$page->data` の各行も `ArticleStatsFactory` で作られる。

docs/tutorial/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ first stats row=MyBlog\ArticleStats commentCount=2 excerpt='Updated body.'
13311331

13321332
### Explanation
13331333

1334-
- `count($pages)` returns the **total item count** from the COUNT query, not the number of pages.
1334+
- `count($pages)` returns the **total item count** from the COUNT query, not the number of pages. For the page count call `$pages->getNbPages()`, which reuses the same COUNT.
13351335
- `$pages[1]` accesses page 1 and lazily executes SELECT with LIMIT/OFFSET.
13361336
- `$page->data` contains a list of `Article` objects because of `@return Pages<Article>`.
13371337
- With `#[DbQuery(factory: ArticleStatsFactory::class)]` and `#[Pager]` together, Ray.MediaQuery 1.1+ builds each row in `$page->data` through `ArticleStatsFactory`.

0 commit comments

Comments
 (0)