0 follower

Trait Yiisoft\ActiveRecord\Trait\CustomConnectionTrait

Trait to implement a custom connection name for ActiveRecord.

See also Yiisoft\ActiveRecord\AbstractActiveRecord::db().

Public Methods

Hide inherited methods

Method Description Defined By
db() Yiisoft\ActiveRecord\Trait\CustomConnectionTrait
withConnectionName() Sets the connection name for the ActiveRecord. Yiisoft\ActiveRecord\Trait\CustomConnectionTrait

Method Details

Hide inherited methods

db() public method

public db( ): \Yiisoft\Db\Connection\ConnectionInterface

                public function db(): ConnectionInterface
{
    if (!empty($this->connectionName)) {
        return ConnectionProvider::get($this->connectionName);
    }
    return parent::db();
}

            
withConnectionName() public method

Sets the connection name for the ActiveRecord.

public withConnectionName( string $connectionName ): Yiisoft\ActiveRecord\Trait\CustomConnectionTrait
$connectionName string

                public function withConnectionName(string $connectionName): static
{
    $new = clone $this;
    $new->connectionName = $connectionName;
    return $new;
}