Skip to content

Commit bbbdbde

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

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,41 @@ changes made:
210210
`$this->getSchema()` inside the `initialize()` method.
211211
- `SaveOptionsBuilder` has been removed. Use a normal array for options instead.
212212

213+
### Known Issues
214+
215+
**Memory Usage with extract() on Large Result Sets**
216+
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.
220+
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**:
225+
226+
``` 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+
}
235+
```
236+
237+
**Option 2: Build your list while iterating**:
238+
239+
``` php
240+
$query = $articles->find()->select(['id', 'title'])->disableHydration();
241+
242+
$ids = [];
243+
foreach ($query as $row) {
244+
$ids[] = $row['id'];
245+
}
246+
```
247+
213248
### Routing
214249

215250
- 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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,40 @@ The [Collections](../core-libraries/collections) chapter has more detail on what
10591059
done with result sets using the collections features. The [Format Results](../orm/query-builder#format-results)
10601060
section show how you can add calculated fields, or replace the result set.
10611061

1062+
> [!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:
1066+
>
1067+
> **Option 1: Use disableHydration() with manual extraction**:
1068+
>
1069+
> ``` 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+
> }
1078+
> ```
1079+
>
1080+
> **Option 2: Select only the fields you need**:
1081+
>
1082+
> ``` php
1083+
> $query = $articles->find()
1084+
> ->select(['id', 'title'])
1085+
> ->disableHydration();
1086+
>
1087+
> $ids = [];
1088+
> foreach ($query as $row) {
1089+
> $ids[] = $row['id'];
1090+
> }
1091+
> ```
1092+
>
1093+
> These approaches avoid loading unnecessary data and provide better memory
1094+
> efficiency for large result sets.
1095+
10621096
### Getting the First & Last Record From a ResultSet
10631097
10641098
You can use the `first()` and `last()` methods to get the respective records

0 commit comments

Comments
 (0)