Skip to content

Commit 10fbeb2

Browse files
Sync documentation updates from cakephp-docs-md
🤖 Generated with GitHub Actions from 2025-10-24 02:33:29 UTC Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent bbbdbde commit 10fbeb2

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

docs/5.x/appendices/5-0-migration-guide.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -212,39 +212,30 @@ changes made:
212212

213213
### Known Issues
214214

215-
**Memory Usage with extract() on Large Result Sets**
215+
**Memory usage with large result sets**
216216

217-
When using `extract()` on large query results, you may experience higher memory
218-
usage compared to CakePHP 4.x. The collection iterator may materialize the entire
219-
result set into memory instead of processing results lazily.
217+
Compared to CakePHP 4.x, when working with large data sets (especially when
218+
calling collection methods like `extract()` on the result set), you may encounter
219+
high memory usage due to the entire result set being buffered in memory.
220220

221-
If you encounter memory issues when extracting values from large result sets,
222-
use one of these workarounds:
223-
224-
**Option 1: Disable hydration and iterate manually**:
221+
You can work around this issue by disabling results buffering for the query:
225222

226223
``` php
227-
$query = $articles->find()
228-
->select(['id'])
229-
->disableHydration();
230-
231-
foreach ($query as $row) {
232-
$id = $row['id'];
233-
// Process each value
234-
}
224+
$results = $articles->find()
225+
->disableBufferedResults()
226+
->all();
235227
```
236228

237-
**Option 2: Build your list while iterating**:
229+
Depending on your use case, you may also consider using disabling hydration:
238230

239231
``` php
240-
$query = $articles->find()->select(['id', 'title'])->disableHydration();
241-
242-
$ids = [];
243-
foreach ($query as $row) {
244-
$ids[] = $row['id'];
245-
}
232+
$results = $articles->find()
233+
->disableHydration()
234+
->all();
246235
```
247236

237+
The above will disable creation of entity objects and return rows as arrays instead.
238+
248239
### Routing
249240

250241
- Static methods `connect()`, `prefix()`, `scope()` and `plugin()` of the `Router` have been removed and

docs/5.x/orm/retrieving-data-and-resultsets.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,38 +1060,27 @@ done with result sets using the collections features. The [Format Results](../or
10601060
section show how you can add calculated fields, or replace the result set.
10611061

10621062
> [!WARNING]
1063-
> When working with large datasets, `extract()` may materialize the entire
1064-
> result set into memory. If you encounter memory issues with large queries,
1065-
> consider these alternatives:
1063+
> When working with large data sets (especially when calling collection methods
1064+
> like `extract()` on the result set), you may encounter high memory usage
1065+
> due to the entire result set being buffered in memory.
10661066
>
1067-
> **Option 1: Use disableHydration() with manual extraction**:
1067+
> You can work around this issue by disabling results buffering for the query:
10681068
>
10691069
> ``` php
1070-
> $query = $articles->find()
1071-
> ->select(['id'])
1072-
> ->disableHydration();
1073-
>
1074-
> foreach ($query as $row) {
1075-
> $id = $row['id'];
1076-
> // Process individual values
1077-
> }
1070+
> $results = $articles->find()
1071+
> ->disableBufferedResults()
1072+
> ->all();
10781073
> ```
10791074
>
1080-
> **Option 2: Select only the fields you need**:
1075+
> Depending on your use case, you may also consider using disabling hydration:
10811076
>
10821077
> ``` php
1083-
> $query = $articles->find()
1084-
> ->select(['id', 'title'])
1085-
> ->disableHydration();
1086-
>
1087-
> $ids = [];
1088-
> foreach ($query as $row) {
1089-
> $ids[] = $row['id'];
1090-
> }
1078+
> $results = $articles->find()
1079+
> ->disableHydration()
1080+
> ->all();
10911081
> ```
10921082
>
1093-
> These approaches avoid loading unnecessary data and provide better memory
1094-
> efficiency for large result sets.
1083+
> The above will disable creation of entity objects and return rows as arrays instead.
10951084
10961085
### Getting the First & Last Record From a ResultSet
10971086

0 commit comments

Comments
 (0)