Final Class Yiisoft\ActiveRecord\LazyLoadException
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Represents an exception thrown by {@see LazyLoadGuard} in the {@see LazyLoadGuardMode::Strict} mode when several records of one result set lazy load the same relation.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getName() | Yiisoft\ |
|
| getSolution() | Yiisoft\ |
Method Details
| public mixed __construct ( string $message, class-string $modelClass, string $relationName ) | ||
| $message | string | |
| $modelClass | class-string | |
| $relationName | string | |
public function __construct(
string $message,
private readonly string $modelClass,
private readonly string $relationName,
) {
parent::__construct($message);
}
| public string getName ( ) |
public function getName(): string
{
return 'Relation is lazy loaded by several records of one result set';
}
| public ?string getSolution ( ) |
public function getSolution(): ?string
{
return <<<SOLUTION
Every record runs a query of its own to load the relation. Eager load it with the query that reads
the records, so that the relation is read with a single query:
```php
\$records = \\{$this->modelClass}::query()->with('$this->relationName')->all();
```
When the lazy loads are intentional, switch the guard to `LazyLoadGuardMode::Log` to keep reporting
them without throwing.
SOLUTION;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.