Lazy Collections ================ To create a lazy collection you can extend the ``Doctrine\Common\Collections\AbstractLazyCollection`` class and define the ``doInitialize`` method. Here is an example where we lazily query the database for a collection of user records: .. code-block:: php use Doctrine\DBAL\Connection; class UsersLazyCollection extends AbstractLazyCollection { /** @var Connection */ private $connection; public function __construct(Connection $connection) { $this->connection = $connection; } protected function doInitialize() : void { $this->collection = $this->connection->fetchAll('SELECT * FROM users'); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
derived-collections.rst | File | 738 B | 0644 |
|
expression-builder.rst | File | 3.46 KB | 0644 |
|
expressions.rst | File | 2.17 KB | 0644 |
|
index.rst | File | 8.21 KB | 0644 |
|
lazy-collections.rst | File | 740 B | 0644 |
|
sidebar.rst | File | 122 B | 0644 |
|