sfDoctrineMasterSlavePlugin和I18N错误“;未知关系别名翻译”;


sfDoctrineMasterSlavePlugin and I18N error "Unknown relation alias Translation"

我正在开发Symfony 1.4应用程序,我使用原则I18N。出于灵活性的需要,我正在迁移我的数据库体系结构,因此我将拥有2个MySQL数据库:1个主数据库和1个从数据库。这就是为什么我决定使用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

我找不出任何理由解释为什么这种关系不能正常工作!。。。我发现有些人也犯了同样的错误,但没有找到任何解决方案。。。

有人有主意吗?

多亏了来自http://www.doctrine-project.org/jira/browse/DC-363(请参阅帖子了解解释)

在lib/vvendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vvendor/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();
        }
    }

    /* ... */
}