0 follower

Final Class Yiisoft\ActiveRecord\JoinWith

InheritanceYiisoft\ActiveRecord\JoinWith

Public Properties

Hide inherited properties

Property Type Description Defined By
$relations array Yiisoft\ActiveRecord\JoinWith

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\ActiveRecord\JoinWith
getJoinType() Returns the join type based on the relation name. Yiisoft\ActiveRecord\JoinWith
getWith() Returns the list of relations to be loaded, filtered according to the eagerLoading configuration. Yiisoft\ActiveRecord\JoinWith
withoutEagerLoading() Creates a new instance without eager loading. Yiisoft\ActiveRecord\JoinWith

Property Details

Hide inherited properties

$relations public property
public array $relations null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( array $relations, array|boolean $eagerLoading, array|string $joinType )
$relations array
$eagerLoading array|boolean
$joinType array|string

                public function __construct(
    public readonly array $relations,
    private array|bool $eagerLoading,
    private readonly array|string $joinType,
) {}

            
getJoinType() public method

Returns the join type based on the relation name.

public string getJoinType ( string $name )
$name string

The relation name.

return string

The real join type.

                public function getJoinType(string $name): string
{
    return is_array($this->joinType)
        ? ($this->joinType[$name] ?? 'INNER JOIN')
        : $this->joinType;
}

            
getWith() public method

Returns the list of relations to be loaded, filtered according to the eagerLoading configuration.

If eagerLoading is an array, only relations whose names are present in the array will be included. If eagerLoading is true, all relations will be included. If eagerLoading is false, no relations will be included.

public array getWith ( )
return array

The filtered list of relations to be loaded.

                public function getWith(): array
{
    if (is_array($this->eagerLoading)) {
        $with = $this->relations;
        foreach ($with as $name => $callback) {
            if (is_int($name)) {
                if (!in_array($callback, $this->eagerLoading, true)) {
                    unset($with[$name]);
                }
            } elseif (!in_array($name, $this->eagerLoading, true)) {
                unset($with[$name]);
            }
        }
        return $with;
    }
    return $this->eagerLoading ? $this->relations : [];
}

            
withoutEagerLoading() public method

Creates a new instance without eager loading.

public self withoutEagerLoading ( )
return self

A new instance without eager loading.

                public function withoutEagerLoading(): self
{
    $new = clone $this;
    $new->eagerLoading = false;
    return $new;
}