Skip to content

Commit

Permalink
Add exception when the connection is not configured. (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Sep 21, 2020
1 parent 364bec7 commit 91edba7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/BaseActiveRecordTrait.php
Expand Up @@ -12,6 +12,7 @@
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Connection\ConnectionPool;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\UnknownMethodException;
use Yiisoft\Db\Exception\UnknownPropertyException;
Expand Down Expand Up @@ -323,6 +324,10 @@ public function hasProperty($name, $checkVars = true, $checkBehaviors = true): b

public static function getConnection(): ConnectionInterface
{
if (self::$connectionId === null) {
throw new InvalidConfigException('A db connection is required.');
}

return ConnectionPool::getConnectionPool(self::$connectionId);
}

Expand Down

0 comments on commit 91edba7

Please sign in to comment.