diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index d56b12a3f..9a059fed1 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -12,6 +12,7 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\ExpressionInterface; +use Yiisoft\Db\Query\BatchQueryResultInterface; use Yiisoft\Db\Query\DataReaderInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; @@ -843,8 +844,15 @@ public function getModel(): ActiveRecordInterface return clone $this->model; } + public function batch(int $batchSize = 100): BatchQueryResultInterface + { + /** @psalm-suppress InvalidArgument */ + return parent::batch($batchSize)->indexBy(null)->resultCallback($this->index(...)); + } + protected function index(array $rows): array { + /** @var list $rows */ return ArArrayHelper::index($this->populate($rows), $this->indexBy); }