sfDoctrineMasterSlavePlugin和I18N错误“Unknown relation alias Translation”

时间:2012-02-02 11:42:05

标签: php doctrine symfony-1.4

我正在研究Symfony 1.4应用程序,我使用的是I18N教义。为了满足灵活性需求,我正在迁移我的数据库架构,因此我将拥有2个MySQL数据库:1个Master和1个Slave。这就是我决定使用sfDoctrineMasterSlavePlugin的原因,这对于这种新配置来说似乎是完美的。不幸的是,我现在遇到I18N的一些错误。这是我的配置:

databases.yml里

dev:
  master:
    class: sfDoctrineDatabase
    param:
      dsn:       mysql:host=localhost;dbname=my_db;
      username:  ****
      password:  ****

  slave:
    class: sfDoctrineDatabase
    param:
      dsn:       mysql:host=localhost;dbname=my_db;
      username:  ****
      password:  ****

的schema.yml

Data:
  actAs:
    I18n:
      fields: [name]
  columns:
    name: { type: string(255) }

在我的模板中

<?php echo $data->getName(); ?>

我收到此错误

Unknown relation alias Translation

我找不到为什么这种关系无法正常工作的原因!...我发现有些人得到了同样的错误,但没有找到任何解决方案......

有没有人有想法?

1 个答案:

答案 0 :(得分:1)

感谢来自http://www.doctrine-project.org/jira/browse/DC-363的Joe Siponen,我终于找到了解决方案(请参阅帖子进行解释)

在lib / vendor / symfony / lib / plugins / sfDoctrinePlugin / lib / vendor / doctrine / Doctrine / Record / Generator.php中:

abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract
{
    protected static $lastConnectionHash = null;

    /* ... */

    public function initialize(Doctrine_Table $table)
    {
        if ($this->_initialized) {
            return false;
        }

        $this->_initialized = true;

        $this->initOptions();

        $table->addGenerator($this, get_class($this));

        $this->_options['table'] = $table;

        $ownerClassName = $this->_options['table']->getComponentName();
        $className = $this->_options['className'];
        $this->_options['className'] = str_replace('%CLASS%', $ownerClassName, $className);

        if (isset($this->_options['tableName'])) {
            $ownerTableName = $this->_options['table']->getTableName();
            $tableName = $this->_options['tableName'];
            $this->_options['tableName'] = str_replace('%TABLE%', $ownerTableName, $tableName);
        }

        // check that class doesn't exist (otherwise we cannot create it)
        if ($this->_options['generateFiles'] === false && class_exists($this->_options['className'])) {
            $this->_table = Doctrine_Core::getTable($this->_options['className']);
            return false;
        }

        $currentConnectionHash = spl_object_hash($table->getConnection()->getDbh());

        if ($currentConnectionHash != self::$lastConnectionHash)
        {
            self::$lastConnectionHash = $currentConnectionHash;

            $this->buildTable();

            $fk = $this->buildForeignKeys($this->_options['table']);

            $this->_table->setColumns($fk);

            $this->buildRelation();

            $this->setTableDefinition();
            $this->setUp();

            $this->generateClassFromTable($this->_table);

            $this->buildChildDefinitions();

            $this->_table->initIdentifier();
        }
    }


    /* ... */

}