Trait Yiisoft\ActiveRecord\Trait\CustomConnectionTrait
Trait to implement a custom connection name for ActiveRecord.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| db() | Yiisoft\ |
|
| withConnectionName() | Sets the connection name for the ActiveRecord. | Yiisoft\ |
Method Details
| public \ |
public function db(): ConnectionInterface
{
if (!empty($this->connectionName)) {
return ConnectionProvider::get($this->connectionName);
}
return parent::db();
}
Sets the connection name for the ActiveRecord.
| public static withConnectionName ( string $connectionName ) | ||
| $connectionName | string | |
public function withConnectionName(string $connectionName): static
{
$new = clone $this;
$new->connectionName = $connectionName;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.