【问题标题】:Database Adapter not setting schemas in Phalcon数据库适配器未在 Phalcon 中设置模式
【发布时间】:2014-05-08 22:03:20
【问题描述】:

我的微应用程序有问题,我使用 PostgreSQL 作为数据库,但是我创建的数据库适配器没有为模型设置架构,我需要使用模型管理器手动完成,我该怎么做避免为每个模型手动设置架构?

这就是我创建适配器的方式

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,
));

这行不通

$person = new Person;
$person = $person->findFirst(1);

这行得通:

$person = new Person;
$app->modelsManager->setModelSchema($person, 'myschema');
$person = $person->findFirst(1);

如果我不手动设置架构,则模型对象找不到表,是的,架构变量设置正确。

另外我认为 Phalcon 总是使用公共架构而不是我设置的架构。

谢谢

【问题讨论】:

  • 是否 $person = Person::findFirst();工作吗?
  • 不,我每次都收到此错误消息:在为 Person 转储元数据时,数据库中不存在表“person”

标签: php postgresql phalcon


【解决方案1】:

将此代码添加到您的模型中:

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

现在您再也不需要重新设置它了。调用模型时会自动设置。

【讨论】:

    【解决方案2】:

    覆盖模型中的 getSource()。覆盖架构

    public function getSource() {
        return "my_table_name";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多