yiisoft/yii2 — pull request #2409 by nineinchnick (2014-02-13 00:23:08+00:00)
Title: support for fetching Query results in batches

Resolves #2387 by adding the ability to process Query results in batches.

This PR introduces a `next()` method in db\Query and db\ActiveQuery, which is a wrapper over db\DataProvider. DataProvider can't be used directly, because in ActiveQuery private methods are used to perform lazy loading.

Executing following code, when there are 4 users:
~~~php
$q = app\models\User::find()->with('userProfilePictures');
while(!empty($users=$q->next(2))) {
// process
}
~~~
results in having the following queries:
~~~sql
SELECT * FROM `users`;
SELECT * FROM `user_profile_pictures` WHERE `user_id` IN (1, 2);
SELECT * FROM `user_profile_pictures` WHERE `user_id` IN (3, 4);
~~~

Should other Query implementations also introduce such method? Probably not if there's no cursor available thus there's no gain in batch processing.