Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database connection using PdoFactory when creating a model #1432

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Builder/Component/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function build(): void

$adapterName = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;
unset($configArray['adapter']);
if (isset($configArray['options'])) {
$configArray = $configArray['options'];
}
/** @var AbstractPdo $db */
$db = new $adapterName($configArray);

Expand Down Expand Up @@ -623,7 +626,7 @@ protected function getEntityClassName(ReferenceInterface $reference, string $nam
* @param AbstractPdo $db
* @return array
*/
protected function getReferenceList(string $schema, AbstractPdo $db): array
protected function getReferenceList(?string $schema, AbstractPdo $db): array
{
if ($this->modelOptions->hasOption('referenceList')) {
return $this->modelOptions->getOption('referenceList');
Expand Down
8 changes: 4 additions & 4 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

class Utils
{
const DB_ADAPTER_POSTGRESQL = 'Postgresql';
const DB_ADAPTER_POSTGRESQL = 'postgresql';

const DB_ADAPTER_SQLITE = 'Sqlite';
const DB_ADAPTER_SQLITE = 'sqlite';

/**
* Converts the underscore_notation to the UpperCamelCase
Expand Down Expand Up @@ -107,11 +107,11 @@ public static function resolveDbSchema(Config $config)
return $config->get('schema');
}

if (self::DB_ADAPTER_POSTGRESQL == $config->get('adapter')) {
if (self::DB_ADAPTER_POSTGRESQL === strtolower($config->get('adapter'))) {
return 'public';
}

if (self::DB_ADAPTER_SQLITE == $config->get('adapter')) {
if (self::DB_ADAPTER_SQLITE === strtolower($config->get('adapter'))) {
// SQLite only supports the current database, unless one is
// attached. This is not the case, so don't return a schema.
return null;
Expand Down