0

Final Class Yiisoft\ActiveRecord\LazyLoadException

InheritanceYiisoft\ActiveRecord\LazyLoadException » LogicException
ImplementsYiisoft\FriendlyException\FriendlyExceptionInterface

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.

Method Details

Hide inherited methods

__construct() public method

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);
}

            
getName() public method

public string getName ( )

                public function getName(): string
{
    return 'Relation is lazy loaded by several records of one result set';
}

            
getSolution() public method

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;
}