Skip to content

Commit 9598499

Browse files
author
Samuel Akopyan
committed
Added documentation for chunk method of AR
1 parent bac1162 commit 9598499

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

docs/js/highlight/lang-php.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
"setGuarded",
292292
"CTime",
293293
"getMicrotime",
294+
"chunk",
294295
];
295296

296297
var BUILTINS = {};

docs/pages/models.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1>Development - Models</h1>
1111
<li><a href="#creating_record">Creating Record</a></li>
1212
<li><a href="#updating_record">Updating Record</a></li>
1313
<li><a href="#deleting_record">Deleting Record</a></li>
14-
<li><a href="#reading_record">Reading Record</a></li>
14+
<li><a href="#reading_records">Reading Records</a></li>
1515
<li><a href="#additional_methods">Additional Methods</a></li>
1616
</ul>
1717
</li>
@@ -415,8 +415,8 @@ <h4>Deleting Record</h4>
415415
<br>
416416

417417

418-
<a name="reading_record"></a>
419-
<h4>Reading Record</h4>
418+
<a name="reading_records"></a>
419+
<h4>Reading Records</h4>
420420
To read data from a database table, we can use one of the find methods as follows.
421421

422422
<pre name="dlhl" class="php">
@@ -433,6 +433,20 @@ <h4>Reading Record</h4>
433433
// Finds all rows satisfying the specified conditions with %LIKE%
434434
$news = News:model()->findAll(CConfig::get('db.prefix').$this->_tableTranslation.'.news_text LIKE :keywords', array(':keywords'=>'%'.$keywords.'%'));
435435
</pre>
436+
437+
Reading records with chunks. The chunk method breaks the record set into small parts of a given size
438+
<pre name="dlhl" class="php">
439+
$posts = [];
440+
// 1st parameter - conditions
441+
// 2nd parameter - condition parameters
442+
// 3rd parameter - chunk size
443+
// 4th parameter - callback function
444+
Posts::model()->chunk($conditions, [], 10, function ($records) use(&$posts){
445+
foreach ($records as $key => $record) {
446+
$posts[] = $record;
447+
}
448+
});
449+
</pre>
436450
<br>
437451

438452

0 commit comments

Comments
 (0)