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 \Yiisoft\Db\Connection\ConnectionInterface db ( )

                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 Yiisoft\ActiveRecord\Trait\CustomConnectionTrait withConnectionName ( string $connectionName )
$connectionName string

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