Skip to content

Commit 5a43c4a

Browse files
committed
docs: clarify chunking caveats
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 05ae904 commit 5a43c4a

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎user_guide_src/source/models/model.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ Sometimes, you need to process large amounts of data and would run the risk of r
10151015
This is best used during cronjobs, data exports, or other large tasks. To make this simpler, you can
10161016
process the data in smaller, manageable pieces using the methods below.
10171017

1018+
.. note:: The ``chunk()``, ``chunkRows()``, ``chunkById()``, and ``chunkRowsById()`` methods do not trigger Model callbacks.
1019+
10181020
chunk()
10191021
-------
10201022

@@ -1055,7 +1057,8 @@ If you want the entire ID-based chunk to be passed to the Closure at once, use `
10551057

10561058
.. warning:: ID-based chunking needs the model to define a primary key, and that primary key must be selected.
10571059
If you customize the selected columns, make sure the primary key is included.
1058-
When joining tables, make sure the model table primary key remains available under its normal field name.
1060+
When using joins, the model primary key must remain available under its normal field name,
1061+
and each primary key value must appear only once in the result set. Otherwise, rows may be skipped.
10591062
These methods manage their own primary key ordering and cannot be used with
10601063
``orderBy()``, ``groupBy()``, ``limit()``, ``offset()`` or ``union()``.
10611064
You should also avoid changing primary key values while processing chunks.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$userModel->where('country', 'US')
4+
->chunkById(100, static function ($data) {
5+
// do something.
6+
// $data is a single row of data.
7+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$userModel->where('country', 'US')
4-
->chunkById(100, static function ($data) {
4+
->chunkRowsById(100, static function ($rows) {
55
// do something.
6-
// $data is a single row of data.
6+
// $rows is an array of rows representing a chunk of 100 items.
77
});

‎user_guide_src/source/models/model/072.php‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)