Builder::all()
Fetches all the matching results for the query.
The method will handle querying the database in batches, running bound queries to support unbound fetching.
Return
(TECEventsCustom_TablesV1ModelsGenerator<Model|TECEventsCustom_TablesV1Modelsarray>) A generator of either this Model instances or arrays, depending on the selected output format.
Source
File: src/Events/Custom_Tables/V1/Models/Builder.php
public function all() {
$query_offset = (int) $this->offset;
$query_limit = $this->limit ?: PHP_INT_MAX;
$running_offset = $query_offset;
$running_limit = $query_limit;
$running_tally = 0;
do {
$this->limit = min( $this->batch_size, $running_limit );
$this->offset = $running_offset;
$running_limit -= $this->batch_size;
$running_offset += $this->batch_size;
$batch_results = $this->get();
$found = count( $batch_results );
foreach ( $batch_results as $batch_result ) {
// Yields with a set key to avoid calls to `iterator_to_array` overriding the values on each pass.
yield $running_tally ++ => $batch_result;
}
} while ( $found === $this->batch_size );
}
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |