cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Postgresql schema not set when creating new DbAdapter

Open CheckMater opened this issue 12 years ago • 4 comments

No matter which schema you set when creating the DbAdapter it always uses the public schema:

use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter;
...
return new DbAdapter(array(
    "host" => $config->database->host,
    "username" => $config->database->username,
    "password" => $config->database->password,
    "dbname" => $config->database->dbname,
    "schema" => $config->database->schema,
));

The only fix for this is manually setting the schema in the initialise method in the model object in this way:

public function initialize() {
$this->getModelsManager()->setModelSchema($this, 'the_schema_name');
}

Which I think is unnecessary since the schema must be set in the adapter creation.

I posted this in the Phalcon forum: http://forum.phalconphp.com/discussion/2251/database-adapter-not-setting-schemas-in-postgresql

Greetings!

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

CheckMater avatar Oct 24 '14 03:10 CheckMater

Whether can create set it.

$config = array(
    "host" => "192.168.1.1",
    "dbname" => "blog",
    "username" => "postgres",
    "password" => "",
    "schema" => "the_schema_name",
);
$connection = new Phalcon\Db\Adapter\Pdo\Postgresql($config);

dreamsxin avatar Oct 28 '14 07:10 dreamsxin

Please take a look at the post, I edited the issue to include info from the post.

CheckMater avatar Oct 28 '14 22:10 CheckMater

This is still not yet fixed in version 2.0.10, we have to still use the fix that appear in the first comment or the following if you are trying to set the schema you configured in your default adapter

    function initialize () {
        $config = $this->getDI()->get('db')->getDescriptor();
        $this->getModelsManager()->setModelSchema($this, $config['schema']);
    }

CheckMater avatar May 03 '16 22:05 CheckMater

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Apr 17 '18 01:04 stale[bot]